home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / cpu / z8000 / z8000ops.c < prev    next >
Text File  |  2000-04-23  |  162KB  |  6,506 lines

  1. /*****************************************************************************
  2.  *
  3.  *     z8000ops.c
  4.  *     Portable Z8000(2) emulator
  5.  *     Opcode functions
  6.  *
  7.  *     Copyright (c) 1998 Juergen Buchmueller, all rights reserved.
  8.  *     Bug fixes and MSB_FIRST compliance Ernesto Corvi.
  9.  *
  10.  *     - This source code is released as freeware for non-commercial purposes.
  11.  *     - You are free to use and redistribute this code in modified or
  12.  *       unmodified form, provided you list me in the credits.
  13.  *     - If you modify this source code, you must add a notice to each modified
  14.  *       source file that it has been changed.  If you're a nice person, you
  15.  *       will clearly mark each change too.  :)
  16.  *     - If you wish to use this for commercial purposes, please contact me at
  17.  *       pullmoll@t-online.de
  18.  *     - The author of this copywritten work reserves the right to change the
  19.  *     terms of its usage and license at any time, including retroactively
  20.  *   - This entire notice must remain in the source code.
  21.  *
  22.  *****************************************************************************/
  23.  
  24. /******************************************
  25.  helper functions
  26.  ******************************************/
  27.  
  28. /******************************************
  29.  check new fcw for switch to system mode
  30.  and swap stack pointer if needed
  31.  ******************************************/
  32. INLINE void CHANGE_FCW(UINT16 fcw)
  33. {
  34.     if (fcw & F_S_N) {            /* system mode now? */
  35.         if (!(FCW & F_S_N)) {    /* and not before? */
  36.             UINT16 tmp = RW(SP);
  37.             RW(SP) = NSP;
  38.             NSP = tmp;
  39.         }
  40.     } else {                    /* user mode now */
  41.         if (FCW & F_S_N) {        /* and not before? */
  42.             UINT16 tmp = RW(SP);
  43.             RW(SP) = NSP;
  44.             NSP = tmp;
  45.         }
  46.     }
  47. #if NEW_INTERRUPT_SYSTEM
  48.     if (!(FCW & F_NVIE) && (fcw & F_NVIE) && (Z.irq_state[0] != CLEAR_LINE))
  49.         IRQ_REQ |= Z8000_NVI;
  50.     if (!(FCW & F_VIE) && (fcw & F_VIE) && (Z.irq_state[1] != CLEAR_LINE))
  51.         IRQ_REQ |= Z8000_VI;
  52. #endif
  53.     FCW = fcw;  /* set new FCW */
  54. }
  55.  
  56. INLINE void PUSHW(UINT8 dst, UINT16 value)
  57. {
  58.     RW(dst) -= 2;
  59.     WRMEM_W( RW(dst), value );
  60. }
  61.  
  62. INLINE UINT16 POPW(UINT8 src)
  63. {
  64.     UINT16 result = RDMEM_W( RW(src) );
  65.     RW(src) += 2;
  66.     return result;
  67. }
  68.  
  69. INLINE void PUSHL(UINT8 dst, UINT32 value)
  70. {
  71.     RW(dst) -= 4;
  72.     WRMEM_L( RW(dst), value );
  73. }
  74.  
  75. INLINE UINT32 POPL(UINT8 src)
  76. {
  77.     UINT32 result = RDMEM_L( RW(src) );
  78.     RW(src) += 4;
  79.     return result;
  80. }
  81.  
  82. /* check zero and sign flag for byte, word and long results */
  83. #define CHK_XXXB_ZS if (!result) SET_Z; else if ((INT8) result < 0) SET_S
  84. #define CHK_XXXW_ZS if (!result) SET_Z; else if ((INT16)result < 0) SET_S
  85. #define CHK_XXXL_ZS if (!result) SET_Z; else if ((INT32)result < 0) SET_S
  86. #define CHK_XXXQ_ZS if (!result) SET_Z; else if ((INT64)result < 0) SET_S
  87.  
  88. #define CHK_XXXB_ZSP FCW |= z8000_zsp[result]
  89.  
  90. /* check carry for addition and subtraction */
  91. #define CHK_ADDX_C if (result < dest) SET_C
  92. #define CHK_ADCX_C if (result < dest || (result == dest && value)) SET_C
  93.  
  94. #define CHK_SUBX_C if (result > dest) SET_C
  95. #define CHK_SBCX_C if (result > dest || (result == dest && value)) SET_C
  96.  
  97. /* check half carry for A addition and S subtraction */
  98. #define CHK_ADDB_H  if ((result & 15) < (dest & 15)) SET_H
  99. #define CHK_ADCB_H    if ((result & 15) < (dest & 15) || ((result & 15) == (dest & 15) && (value & 15))) SET_H
  100.  
  101. #define CHK_SUBB_H  if ((result & 15) > (dest & 15)) SET_H
  102. #define CHK_SBCB_H    if ((result & 15) > (dest & 15) || ((result & 15) == (dest & 15) && (value & 15))) SET_H
  103.  
  104. /* check overflow for addition for byte, word and long */
  105. #define CHK_ADDB_V if (((value & dest & ~result) | (~value & ~dest & result)) & S08) SET_V
  106. #define CHK_ADDW_V if (((value & dest & ~result) | (~value & ~dest & result)) & S16) SET_V
  107. #define CHK_ADDL_V if (((value & dest & ~result) | (~value & ~dest & result)) & S32) SET_V
  108.  
  109. /* check overflow for subtraction for byte, word and long */
  110. #define CHK_SUBB_V if (((~value & dest & ~result) | (value & ~dest & result)) & S08) SET_V
  111. #define CHK_SUBW_V if (((~value & dest & ~result) | (value & ~dest & result)) & S16) SET_V
  112. #define CHK_SUBL_V if (((~value & dest & ~result) | (value & ~dest & result)) & S32) SET_V
  113.  
  114.  
  115. /******************************************
  116.  add byte
  117.  flags:  CZSVDH
  118.  ******************************************/
  119. INLINE UINT8 ADDB(UINT8 dest, UINT8 value)
  120. {
  121.     UINT8 result = dest + value;
  122.     CLR_CZSVH;      /* first clear C, Z, S, P/V and H flags    */
  123.     CLR_DA;         /* clear DA (decimal adjust) flag for addb */
  124.     CHK_XXXB_ZS;    /* set Z and S flags for result byte       */
  125.     CHK_ADDX_C;     /* set C if result overflowed               */
  126.     CHK_ADDB_V;     /* set V if result has incorrect sign       */
  127.     CHK_ADDB_H;     /* set H if lower nibble overflowed        */
  128.     return result;
  129. }
  130.  
  131. /******************************************
  132.  add word
  133.  flags:  CZSV--
  134.  ******************************************/
  135. INLINE UINT16 ADDW(UINT16 dest, UINT16 value)
  136. {
  137.     UINT16 result = dest + value;
  138.     CLR_CZSV;       /* first clear C, Z, S, P/V flags          */
  139.     CHK_XXXW_ZS;    /* set Z and S flags for result word       */
  140.     CHK_ADDX_C;     /* set C if result overflowed               */
  141.     CHK_ADDW_V;     /* set V if result has incorrect sign       */
  142.     return result;
  143. }
  144.  
  145. /******************************************
  146.  add long
  147.  flags:  CZSV--
  148.  ******************************************/
  149. INLINE UINT32 ADDL(UINT32 dest, UINT32 value)
  150. {
  151.     UINT32 result = dest + value;
  152.     CLR_CZSV;       /* first clear C, Z, S, P/V flags          */
  153.     CHK_XXXL_ZS;    /* set Z and S flags for result long       */
  154.     CHK_ADDX_C;     /* set C if result overflowed               */
  155.     CHK_ADDL_V;     /* set V if result has incorrect sign       */
  156.     return result;
  157. }
  158.  
  159. /******************************************
  160.  add with carry byte
  161.  flags:  CZSVDH
  162.  ******************************************/
  163. INLINE UINT8 ADCB(UINT8 dest, UINT8 value)
  164. {
  165.     UINT8 result = dest + value + GET_C;
  166.     CLR_CZSVH;      /* first clear C, Z, S, P/V and H flags    */
  167.     CLR_DA;         /* clear DA (decimal adjust) flag for adcb */
  168.     CHK_XXXB_ZS;    /* set Z and S flags for result byte       */
  169.     CHK_ADCX_C;     /* set C if result overflowed               */
  170.     CHK_ADDB_V;     /* set V if result has incorrect sign       */
  171.     CHK_ADCB_H;     /* set H if lower nibble overflowed        */
  172.     return result;
  173. }
  174.  
  175. /******************************************
  176.  add with carry word
  177.  flags:  CZSV--
  178.  ******************************************/
  179. INLINE UINT16 ADCW(UINT16 dest, UINT16 value)
  180. {
  181.     UINT16 result = dest + value + GET_C;
  182.     CLR_CZSV;       /* first clear C, Z, S, P/V flags          */
  183.     CHK_XXXW_ZS;    /* set Z and S flags for result word       */
  184.     CHK_ADCX_C;     /* set C if result overflowed               */
  185.     CHK_ADDW_V;     /* set V if result has incorrect sign       */
  186.     return result;
  187. }
  188.  
  189. /******************************************
  190.  subtract byte
  191.  flags:  CZSVDH
  192.  ******************************************/
  193. INLINE UINT8 SUBB(UINT8 dest, UINT8 value)
  194. {
  195.     UINT8 result = dest - value;
  196.     CLR_CZSVH;      /* first clear C, Z, S, P/V and H flags    */
  197.     SET_DA;         /* set DA (decimal adjust) flag for subb   */
  198.     CHK_XXXB_ZS;    /* set Z and S flags for result byte       */
  199.     CHK_SUBX_C;     /* set C if result underflowed               */
  200.     CHK_SUBB_V;     /* set V if result has incorrect sign       */
  201.     CHK_SUBB_H;     /* set H if lower nibble underflowed       */
  202.     return result;
  203. }
  204.  
  205. /******************************************
  206.  subtract word
  207.  flags:  CZSV--
  208.  ******************************************/
  209. INLINE UINT16 SUBW(UINT16 dest, UINT16 value)
  210. {
  211.     UINT16 result = dest - value;
  212.     CLR_CZSV;       /* first clear C, Z, S, P/V flags          */
  213.     CHK_XXXW_ZS;    /* set Z and S flags for result word       */
  214.     CHK_SUBX_C;     /* set C if result underflowed               */
  215.     CHK_SUBW_V;     /* set V if result has incorrect sign       */
  216.     return result;
  217. }
  218.  
  219. /******************************************
  220.  subtract long
  221.  flags:  CZSV--
  222.  ******************************************/
  223. INLINE UINT32 SUBL(UINT32 dest, UINT32 value)
  224. {
  225.     UINT32 result = dest - value;
  226.     CLR_CZSV;       /* first clear C, Z, S, P/V flags          */
  227.     CHK_XXXL_ZS;    /* set Z and S flags for result long       */
  228.     CHK_SUBX_C;     /* set C if result underflowed               */
  229.     CHK_SUBL_V;     /* set V if result has incorrect sign       */
  230.     return result;
  231. }
  232.  
  233. /******************************************
  234.  subtract with carry byte
  235.  flags:  CZSVDH
  236.  ******************************************/
  237. INLINE UINT8 SBCB(UINT8 dest, UINT8 value)
  238. {
  239.     UINT8 result = dest - value - GET_C;
  240.     CLR_CZSVH;      /* first clear C, Z, S, P/V and H flags    */
  241.     SET_DA;         /* set DA (decimal adjust) flag for sbcb   */
  242.     CHK_XXXB_ZS;    /* set Z and S flags for result byte       */
  243.     CHK_SBCX_C;     /* set C if result underflowed               */
  244.     CHK_SUBB_V;     /* set V if result has incorrect sign       */
  245.     CHK_SBCB_H;     /* set H if lower nibble underflowed       */
  246.     return result;
  247. }
  248.  
  249. /******************************************
  250.  subtract with carry word
  251.  flags:  CZSV--
  252.  ******************************************/
  253. INLINE UINT16 SBCW(UINT16 dest, UINT16 value)
  254. {
  255.     UINT16 result = dest - value - GET_C;
  256.     CLR_CZSV;       /* first clear C, Z, S, P/V flags          */
  257.     CHK_XXXW_ZS;    /* set Z and S flags for result word       */
  258.     CHK_SBCX_C;     /* set C if result underflowed               */
  259.     CHK_SUBW_V;     /* set V if result has incorrect sign       */
  260.     return result;
  261. }
  262.  
  263. /******************************************
  264.  logical or byte
  265.  flags:  -ZSP--
  266.  ******************************************/
  267. INLINE UINT8 ORB(UINT8 dest, UINT8 value)
  268. {
  269.     UINT8 result = dest | value;
  270.     CLR_ZSP;        /* first clear Z, S, P/V flags               */
  271.     CHK_XXXB_ZSP;    /* set Z, S and P flags for result byte    */
  272.     return result;
  273. }
  274.  
  275. /******************************************
  276.  logical or word
  277.  flags:  -ZS---
  278.  ******************************************/
  279. INLINE UINT16 ORW(UINT16 dest, UINT16 value)
  280. {
  281.     UINT16 result = dest | value;
  282.     CLR_ZS;         /* first clear Z, and S flags               */
  283.     CHK_XXXW_ZS;    /* set Z and S flags for result word       */
  284.     return result;
  285. }
  286.  
  287. /******************************************
  288.  logical and byte
  289.  flags:  -ZSP--
  290.  ******************************************/
  291. INLINE UINT8 ANDB(UINT8 dest, UINT8 value)
  292. {
  293.     UINT8 result = dest & value;
  294.     CLR_ZSP;        /* first clear Z,S and P/V flags           */
  295.     CHK_XXXB_ZSP;    /* set Z, S and P flags for result byte    */
  296.     return result;
  297. }
  298.  
  299. /******************************************
  300.  logical and word
  301.  flags:  -ZS---
  302.  ******************************************/
  303. INLINE UINT16 ANDW(UINT16 dest, UINT16 value)
  304. {
  305.     UINT16 result = dest & value;
  306.     CLR_ZS;         /* first clear Z and S flags               */
  307.     CHK_XXXW_ZS;    /* set Z and S flags for result word       */
  308.     return result;
  309. }
  310.  
  311. /******************************************
  312.  logical exclusive or byte
  313.  flags:  -ZSP--
  314.  ******************************************/
  315. INLINE UINT8 XORB(UINT8 dest, UINT8 value)
  316. {
  317.     UINT8 result = dest ^ value;
  318.     CLR_ZSP;        /* first clear Z, S and P/V flags          */
  319.     CHK_XXXB_ZSP;    /* set Z, S and P flags for result byte    */
  320.     return result;
  321. }
  322.  
  323. /******************************************
  324.  logical exclusive or word
  325.  flags:  -ZS---
  326.  ******************************************/
  327. INLINE UINT16 XORW(UINT16 dest, UINT16 value)
  328. {
  329.     UINT16 result = dest ^ value;
  330.     CLR_ZS;         /* first clear Z and S flags               */
  331.     CHK_XXXW_ZS;    /* set Z and S flags for result word       */
  332.     return result;
  333. }
  334.  
  335.  
  336. /******************************************
  337.  compare byte
  338.  flags:  CZSV--
  339.  ******************************************/
  340. INLINE void CPB(UINT8 dest, UINT8 value)
  341. {
  342.     UINT8 result = dest - value;
  343.     CLR_CZSV;       /* first clear C, Z, S and P/V flags       */
  344.     CHK_XXXB_ZS;    /* set Z and S flags for result byte       */
  345.     CHK_SUBX_C;     /* set C if result underflowed               */
  346.     CHK_SUBB_V;
  347. }
  348.  
  349. /******************************************
  350.  compare word
  351.  flags:  CZSV--
  352.  ******************************************/
  353. INLINE void CPW(UINT16 dest, UINT16 value)
  354. {
  355.     UINT16 result = dest - value;
  356.     CLR_CZSV;
  357.     CHK_XXXW_ZS;    /* set Z and S flags for result word       */
  358.     CHK_SUBX_C;     /* set C if result underflowed               */
  359.     CHK_SUBW_V;
  360. }
  361.  
  362. /******************************************
  363.  compare long
  364.  flags:  CZSV--
  365.  ******************************************/
  366. INLINE void CPL(UINT32 dest, UINT32 value)
  367. {
  368.     UINT32 result = dest - value;
  369.     CLR_CZSV;
  370.     CHK_XXXL_ZS;    /* set Z and S flags for result long       */
  371.     CHK_SUBX_C;     /* set C if result underflowed               */
  372.     CHK_SUBL_V;
  373. }
  374.  
  375. /******************************************
  376.  complement byte
  377.  flags: -ZSP--
  378.  ******************************************/
  379. INLINE UINT8 COMB(UINT8 dest)
  380. {
  381.     UINT8 result = ~dest;
  382.     CLR_ZSP;
  383.     CHK_XXXB_ZSP;    /* set Z, S and P flags for result byte    */
  384.     return result;
  385. }
  386.  
  387. /******************************************
  388.  complement word
  389.  flags: -ZS---
  390.  ******************************************/
  391. INLINE UINT16 COMW(UINT16 dest)
  392. {
  393.     UINT16 result = ~dest;
  394.     CLR_ZS;
  395.     CHK_XXXW_ZS;    /* set Z and S flags for result word       */
  396.     return result;
  397. }
  398.  
  399. /******************************************
  400.  negate byte
  401.  flags:  CZSV--
  402.  ******************************************/
  403. INLINE UINT8 NEGB(UINT8 dest)
  404. {
  405.     UINT8 result = (UINT8) -dest;
  406.     CLR_CZSV;
  407.     CHK_XXXB_ZS;    /* set Z and S flags for result byte       */
  408.     if (result > 0) SET_C;
  409.     if (result == S08) SET_V;
  410.     return result;
  411. }
  412.  
  413. /******************************************
  414.  negate word
  415.  flags:  CZSV--
  416.  ******************************************/
  417. INLINE UINT16 NEGW(UINT16 dest)
  418. {
  419.     UINT16 result = (UINT16) -dest;
  420.     CLR_CZSV;
  421.     CHK_XXXW_ZS;    /* set Z and S flags for result word       */
  422.     if (result > 0) SET_C;
  423.     if (result == S16) SET_V;
  424.     return result;
  425. }
  426.  
  427. /******************************************
  428.  test byte
  429.  flags:  -ZSP--
  430.  ******************************************/
  431. INLINE void TESTB(UINT8 result)
  432. {
  433.     CLR_ZSP;
  434.     CHK_XXXB_ZSP;    /* set Z and S flags for result byte       */
  435. }
  436.  
  437. /******************************************
  438.  test word
  439.  flags:  -ZS---
  440.  ******************************************/
  441. INLINE void TESTW(UINT16 dest)
  442. {
  443.     CLR_ZS;
  444.     if (!dest) SET_Z; else if (dest & S16) SET_S;
  445. }
  446.  
  447. /******************************************
  448.  test long
  449.  flags:  -ZS---
  450.  ******************************************/
  451. INLINE void TESTL(UINT32 dest)
  452. {
  453.     CLR_ZS;
  454.     if (!dest) SET_Z; else if (dest & S32) SET_S;
  455. }
  456.  
  457. /******************************************
  458.  increment byte
  459.  flags: -ZSV--
  460.  ******************************************/
  461. INLINE UINT8 INCB(UINT8 dest, UINT8 value)
  462. {
  463.     UINT8 result = dest + value;
  464.     CLR_ZSV;
  465.     CHK_XXXB_ZS;    /* set Z and S flags for result byte       */
  466.     CHK_ADDB_V;     /* set V if result overflowed               */
  467.     return result;
  468. }
  469.  
  470. /******************************************
  471.  increment word
  472.  flags: -ZSV--
  473.  ******************************************/
  474. INLINE UINT16 INCW(UINT16 dest, UINT16 value)
  475. {
  476.     UINT16 result = dest + value;
  477.     CLR_ZSV;
  478.     CHK_XXXW_ZS;    /* set Z and S flags for result byte       */
  479.     CHK_ADDW_V;     /* set V if result overflowed               */
  480.     return result;
  481. }
  482.  
  483. /******************************************
  484.  decrement byte
  485.  flags: -ZSV--
  486.  ******************************************/
  487. INLINE UINT8 DECB(UINT8 dest, UINT8 value)
  488. {
  489.     UINT8 result = dest - value;
  490.     CLR_ZSV;
  491.     CHK_XXXB_ZS;    /* set Z and S flags for result byte       */
  492.     CHK_SUBB_V;     /* set V if result overflowed               */
  493.     return result;
  494. }
  495.  
  496. /******************************************
  497.  decrement word
  498.  flags: -ZSV--
  499.  ******************************************/
  500. INLINE UINT16 DECW(UINT16 dest, UINT16 value)
  501. {
  502.     UINT16 result = dest - value;
  503.     CLR_ZSV;
  504.     CHK_XXXW_ZS;    /* set Z and S flags for result word       */
  505.     CHK_SUBW_V;     /* set V if result overflowed               */
  506.     return result;
  507. }
  508.  
  509. /******************************************
  510.  multiply words
  511.  flags:  CZSV--
  512.  ******************************************/
  513. INLINE UINT32 MULTW(UINT16 dest, UINT16 value)
  514. {
  515.     UINT32 result = (INT32)(INT16)dest * (INT16)value;
  516.     CLR_CZSV;
  517.     CHK_XXXL_ZS;
  518.     if( !value )
  519.     {
  520.         /* multiplication with zero is faster */
  521.         z8000_ICount += (70-18);
  522.     }
  523.     if( (INT32)result < -0x7fff || (INT32)result >= 0x7fff ) SET_C;
  524.     return result;
  525. }
  526.  
  527. /******************************************
  528.  multiply longs
  529.  flags:  CZSV--
  530.  ******************************************/
  531. INLINE UINT64 MULTL(UINT32 dest, UINT32 value)
  532. {
  533.     UINT64 result = (INT64)(INT32)dest * (INT32)value;
  534.     if( !value )
  535.     {
  536.         /* multiplication with zero is faster */
  537.         z8000_ICount += (282 - 30);
  538.     }
  539.     else
  540.     {
  541.         int n;
  542.         for( n = 0; n < 32; n++ )
  543.             if( dest & (1L << n) ) z8000_ICount -= 7;
  544.     }
  545.     CLR_CZSV;
  546.     CHK_XXXQ_ZS;
  547.     if( (INT64)result < -0x7fffffffL || (INT64)result >= 0x7fffffffL ) SET_C;
  548.     return result;
  549. }
  550.  
  551. /******************************************
  552.  divide long by word
  553.  flags: CZSV--
  554.  ******************************************/
  555. INLINE UINT32 DIVW(UINT32 dest, UINT16 value)
  556. {
  557.     UINT32 result = dest;
  558.     UINT16 remainder = 0;
  559.     CLR_CZSV;
  560.     if (value)
  561.     {
  562.         UINT16 qsign = ((dest >> 16) ^ value) & S16;
  563.         UINT16 rsign = (dest >> 16) & S16;
  564.         if ((INT32)dest < 0) dest = -dest;
  565.         if ((INT16)value < 0) value = -value;
  566.         result = dest / value;
  567.         remainder = dest % value;
  568.         if (qsign) result = -result;
  569.         if (rsign) remainder = -remainder;
  570.         if ((INT32)result < -0x8000 || (INT32)result > 0x7fff)
  571.         {
  572.             INT32 temp = (INT32)result >> 1;
  573.             SET_V;
  574.             if (temp >= -0x8000 && temp <= 0x7fff)
  575.             {
  576.                 result = (temp < 0) ? -1 : 0;
  577.                 CHK_XXXW_ZS;
  578.                 SET_C;
  579.             }
  580.         }
  581.         else
  582.         {
  583.             CHK_XXXW_ZS;
  584.         }
  585.         result = ((UINT32)remainder << 16) | (result & 0xffff);
  586.     }
  587.     else
  588.     {
  589.         SET_Z;
  590.         SET_V;
  591.     }
  592.     return result;
  593. }
  594.  
  595. /******************************************
  596.  divide quad word by long
  597.  flags: CZSV--
  598.  ******************************************/
  599. INLINE UINT64 DIVL(UINT64 dest, UINT32 value)
  600. {
  601.     UINT64 result = dest;
  602.     UINT32 remainder = 0;
  603.     CLR_CZSV;
  604.     if (value)
  605.     {
  606.         UINT32 qsign = ((dest >> 32) ^ value) & S32;
  607.         UINT32 rsign = (dest >> 32) & S32;
  608.         if ((INT64)dest < 0) dest = -dest;
  609.         if ((INT32)value < 0) value = -value;
  610.         result = dest / value;
  611.         remainder = dest % value;
  612.         if (qsign) result = -result;
  613.         if (rsign) remainder = -remainder;
  614.         if ((INT64)result < -0x80000000 || (INT64)result > 0x7fffffff)
  615.         {
  616.             INT64 temp = (INT64)result >> 1;
  617.             SET_V;
  618.             if (temp >= -0x80000000 && temp <= 0x7fffffff)
  619.             {
  620.                 result = (temp < 0) ? -1 : 0;
  621.                 CHK_XXXL_ZS;
  622.                 SET_C;
  623.             }
  624.         }
  625.         else
  626.         {
  627.             CHK_XXXL_ZS;
  628.         }
  629.         result = ((UINT64)remainder << 32) | (result & 0xffffffff);
  630.     }
  631.     else
  632.     {
  633.         SET_Z;
  634.         SET_V;
  635.     }
  636.     return result;
  637. }
  638.  
  639. /******************************************
  640.  rotate left byte
  641.  flags:  CZSV--
  642.  ******************************************/
  643. INLINE UINT8 RLB(UINT8 dest, UINT8 twice)
  644. {
  645.     UINT8 result = (dest << 1) | (dest >> 7);
  646.     CLR_CZSV;
  647.     if (twice) result = (result << 1) | (result >> 7);
  648.     CHK_XXXB_ZS;    /* set Z and S flags for result byte       */
  649.     if (result & 0x01) SET_C;
  650.     if ((result ^ dest) & S08) SET_V;
  651.     return result;
  652. }
  653.  
  654. /******************************************
  655.  rotate left word
  656.  flags:  CZSV--
  657.  ******************************************/
  658. INLINE UINT16 RLW(UINT16 dest, UINT8 twice)
  659. {
  660.     UINT16 result = (dest << 1) | (dest >> 15);
  661.     CLR_CZSV;
  662.     if (twice) result = (result << 1) | (result >> 15);
  663.     CHK_XXXW_ZS;    /* set Z and S flags for result word       */
  664.     if (result & 0x0001) SET_C;
  665.     if ((result ^ dest) & S16) SET_V;
  666.     return result;
  667. }
  668.  
  669. /******************************************
  670.  rotate left through carry byte
  671.  flags:  CZSV--
  672.  ******************************************/
  673. INLINE UINT8 RLCB(UINT8 dest, UINT8 twice)
  674. {
  675.     UINT8 c = dest & S08;
  676.     UINT8 result = (dest << 1) | GET_C;
  677.     CLR_CZSV;
  678.     if (twice) {
  679.         UINT8 c1 = c >> 7;
  680.         c = result & S08;
  681.         result = (result << 1) | c1;
  682.     }
  683.     CHK_XXXB_ZS;    /* set Z and S flags for result byte       */
  684.     if (c) SET_C;
  685.     if ((result ^ dest) & S08) SET_V;
  686.     return result;
  687. }
  688.  
  689. /******************************************
  690.  rotate left through carry word
  691.  flags:  CZSV--
  692.  ******************************************/
  693. INLINE UINT16 RLCW(UINT16 dest, UINT8 twice)
  694. {
  695.     UINT16 c = dest & S16;
  696.     UINT16 result = (dest << 1) | GET_C;
  697.     CLR_CZSV;
  698.     if (twice) {
  699.         UINT16 c1 = c >> 15;
  700.         c = result & S16;
  701.         result = (result << 1) | c1;
  702.     }
  703.     CHK_XXXW_ZS;    /* set Z and S flags for result word       */
  704.     if (c) SET_C;
  705.     if ((result ^ dest) & S16) SET_V;
  706.     return result;
  707. }
  708.  
  709. /******************************************
  710.  rotate right byte
  711.  flags:  CZSV--
  712.  ******************************************/
  713. INLINE UINT8 RRB(UINT8 dest, UINT8 twice)
  714. {
  715.     UINT8 result = (dest >> 1) | (dest << 7);
  716.     CLR_CZSV;
  717.     if (twice) result = (result >> 1) | (result << 7);
  718.     if (!result) SET_Z; else if (result & S08) SET_SC;
  719.     if ((result ^ dest) & S08) SET_V;
  720.     return result;
  721. }
  722.  
  723. /******************************************
  724.  rotate right word
  725.  flags:  CZSV--
  726.  ******************************************/
  727. INLINE UINT16 RRW(UINT16 dest, UINT8 twice)
  728. {
  729.     UINT16 result = (dest >> 1) | (dest << 15);
  730.     CLR_CZSV;
  731.     if (twice) result = (result >> 1) | (result << 15);
  732.     if (!result) SET_Z; else if (result & S16) SET_SC;
  733.     if ((result ^ dest) & S16) SET_V;
  734.     return result;
  735. }
  736.  
  737. /******************************************
  738.  rotate right through carry byte
  739.  flags:  CZSV--
  740.  ******************************************/
  741. INLINE UINT8 RRCB(UINT8 dest, UINT8 twice)
  742. {
  743.     UINT8 c = dest & 1;
  744.     UINT8 result = (dest >> 1) | (GET_C << 7);
  745.     CLR_CZSV;
  746.     if (twice) {
  747.         UINT8 c1 = c << 7;
  748.         c = result & 1;
  749.         result = (result >> 1) | c1;
  750.     }
  751.     CHK_XXXB_ZS;    /* set Z and S flags for result byte       */
  752.     if (c) SET_C;
  753.     if ((result ^ dest) & S08) SET_V;
  754.     return result;
  755. }
  756.  
  757. /******************************************
  758.  rotate right through carry word
  759.  flags:  CZSV--
  760.  ******************************************/
  761. INLINE UINT16 RRCW(UINT16 dest, UINT8 twice)
  762. {
  763.     UINT16 c = dest & 1;
  764.     UINT16 result = (dest >> 1) | (GET_C << 15);
  765.     CLR_CZSV;
  766.     if (twice) {
  767.         UINT16 c1 = c << 15;
  768.         c = result & 1;
  769.         result = (result >> 1) | c1;
  770.     }
  771.     CHK_XXXW_ZS;    /* set Z and S flags for result word       */
  772.     if (c) SET_C;
  773.     if ((result ^ dest) & S16) SET_V;
  774.     return result;
  775. }
  776.  
  777. /******************************************
  778.  shift dynamic arithmetic byte
  779.  flags:  CZSV--
  780.  ******************************************/
  781. INLINE UINT8 SDAB(UINT8 dest, INT8 count)
  782. {
  783.     INT8 result = (INT8) dest;
  784.     UINT8 c = 0;
  785.     CLR_CZSV;
  786.     while (count > 0) {
  787.         c = result & S08;
  788.         result <<= 1;
  789.         count--;
  790.     }
  791.     while (count < 0) {
  792.         c = result & 0x01;
  793.         result >>= 1;
  794.         count++;
  795.     }
  796.     CHK_XXXB_ZS;    /* set Z and S flags for result byte       */
  797.     if (c) SET_C;
  798.     if ((result ^ dest) & S08) SET_V;
  799.     return (UINT8)result;
  800. }
  801.  
  802. /******************************************
  803.  shift dynamic arithmetic word
  804.  flags:  CZSV--
  805.  ******************************************/
  806. INLINE UINT16 SDAW(UINT16 dest, INT8 count)
  807. {
  808.     INT16 result = (INT16) dest;
  809.     UINT16 c = 0;
  810.     CLR_CZSV;
  811.     while (count > 0) {
  812.         c = result & S16;
  813.         result <<= 1;
  814.         count--;
  815.     }
  816.     while (count < 0) {
  817.         c = result & 0x0001;
  818.         result >>= 1;
  819.         count++;
  820.     }
  821.     CHK_XXXW_ZS;    /* set Z and S flags for result word       */
  822.     if (c) SET_C;
  823.     if ((result ^ dest) & S16) SET_V;
  824.     return (UINT16)result;
  825. }
  826.  
  827. /******************************************
  828.  shift dynamic arithmetic long
  829.  flags:  CZSV--
  830.  ******************************************/
  831. INLINE UINT32 SDAL(UINT32 dest, INT8 count)
  832. {
  833.     INT32 result = (INT32) dest;
  834.     UINT32 c = 0;
  835.     CLR_CZSV;
  836.     while (count > 0) {
  837.         c = result & S32;
  838.         result <<= 1;
  839.         count--;
  840.     }
  841.     while (count < 0) {
  842.         c = result & 0x00000001;
  843.         result >>= 1;
  844.         count++;
  845.     }
  846.     CHK_XXXL_ZS;    /* set Z and S flags for result long       */
  847.     if (c) SET_C;
  848.     if ((result ^ dest) & S32) SET_V;
  849.     return (UINT32) result;
  850. }
  851.  
  852. /******************************************
  853.  shift dynamic logic byte
  854.  flags:  CZSV--
  855.  ******************************************/
  856. INLINE UINT8 SDLB(UINT8 dest, INT8 count)
  857. {
  858.     UINT8 result = dest;
  859.     UINT8 c = 0;
  860.     CLR_CZSV;
  861.     while (count > 0) {
  862.         c = result & S08;
  863.         result <<= 1;
  864.         count--;
  865.     }
  866.     while (count < 0) {
  867.         c = result & 0x01;
  868.         result >>= 1;
  869.         count++;
  870.     }
  871.     CHK_XXXB_ZS;    /* set Z and S flags for result byte       */
  872.     if (c) SET_C;
  873.     if ((result ^ dest) & S08) SET_V;
  874.     return result;
  875. }
  876.  
  877. /******************************************
  878.  shift dynamic logic word
  879.  flags:  CZSV--
  880.  ******************************************/
  881. INLINE UINT16 SDLW(UINT16 dest, INT8 count)
  882. {
  883.     UINT16 result = dest;
  884.     UINT16 c = 0;
  885.     CLR_CZSV;
  886.     while (count > 0) {
  887.         c = result & S16;
  888.         result <<= 1;
  889.         count--;
  890.     }
  891.     while (count < 0) {
  892.         c = result & 0x0001;
  893.         result >>= 1;
  894.         count++;
  895.     }
  896.     CHK_XXXW_ZS;    /* set Z and S flags for result word       */
  897.     if (c) SET_C;
  898.     if ((result ^ dest) & S16) SET_V;
  899.     return result;
  900. }
  901.  
  902. /******************************************
  903.  shift dynamic logic long
  904.  flags:  CZSV--
  905.  ******************************************/
  906. INLINE UINT32 SDLL(UINT32 dest, INT8 count)
  907. {
  908.     UINT32 result = dest;
  909.     UINT32 c = 0;
  910.     CLR_CZSV;
  911.     while (count > 0) {
  912.         c = result & S32;
  913.         result <<= 1;
  914.         count--;
  915.     }
  916.     while (count < 0) {
  917.         c = result & 0x00000001;
  918.         result >>= 1;
  919.         count++;
  920.     }
  921.     CHK_XXXL_ZS;    /* set Z and S flags for result long       */
  922.     if (c) SET_C;
  923.     if ((result ^ dest) & S32) SET_V;
  924.     return result;
  925. }
  926.  
  927. /******************************************
  928.  shift left arithmetic byte
  929.  flags:  CZSV--
  930.  ******************************************/
  931. INLINE UINT8 SLAB(UINT8 dest, UINT8 count)
  932. {
  933.     UINT8 c = (count) ? (dest << (count - 1)) & S08 : 0;
  934.     UINT8 result = (UINT8)((INT8)dest << count);
  935.     CLR_CZSV;
  936.     CHK_XXXB_ZS;    /* set Z and S flags for result byte       */
  937.     if (c) SET_C;
  938.     if ((result ^ dest) & S08) SET_V;
  939.     return result;
  940. }
  941.  
  942. /******************************************
  943.  shift left arithmetic word
  944.  flags:  CZSV--
  945.  ******************************************/
  946. INLINE UINT16 SLAW(UINT16 dest, UINT8 count)
  947. {
  948.     UINT16 c = (count) ? (dest << (count - 1)) & S16 : 0;
  949.     UINT16 result = (UINT16)((INT16)dest << count);
  950.     CLR_CZSV;
  951.     CHK_XXXW_ZS;    /* set Z and S flags for result word       */
  952.     if (c) SET_C;
  953.     if ((result ^ dest) & S16) SET_V;
  954.     return result;
  955. }
  956.  
  957. /******************************************
  958.  shift left arithmetic long
  959.  flags:  CZSV--
  960.  ******************************************/
  961. INLINE UINT32 SLAL(UINT32 dest, UINT8 count)
  962. {
  963.     UINT32 c = (count) ? (dest << (count - 1)) & S32 : 0;
  964.     UINT32 result = (UINT32)((INT32)dest << count);
  965.     CLR_CZSV;
  966.     CHK_XXXL_ZS;    /* set Z and S flags for result long       */
  967.     if (c) SET_C;
  968.     if ((result ^ dest) & S32) SET_V;
  969.     return result;
  970. }
  971.  
  972. /******************************************
  973.  shift left logic byte
  974.  flags:  CZS---
  975.  ******************************************/
  976. INLINE UINT8 SLLB(UINT8 dest, UINT8 count)
  977. {
  978.     UINT8 c = (count) ? (dest << (count - 1)) & S08 : 0;
  979.     UINT8 result = dest << count;
  980.     CLR_CZS;
  981.     CHK_XXXB_ZS;    /* set Z and S flags for result byte       */
  982.     if (c) SET_C;
  983.     return result;
  984. }
  985.  
  986. /******************************************
  987.  shift left logic word
  988.  flags:  CZS---
  989.  ******************************************/
  990. INLINE UINT16 SLLW(UINT16 dest, UINT8 count)
  991. {
  992.     UINT16 c = (count) ? (dest << (count - 1)) & S16 : 0;
  993.     UINT16 result = dest << count;
  994.     CLR_CZS;
  995.     CHK_XXXW_ZS;    /* set Z and S flags for result word       */
  996.     if (c) SET_C;
  997.     return result;
  998. }
  999.  
  1000. /******************************************
  1001.  shift left logic long
  1002.  flags:  CZS---
  1003.  ******************************************/
  1004. INLINE UINT32 SLLL(UINT32 dest, UINT8 count)
  1005. {
  1006.     UINT32 c = (count) ? (dest << (count - 1)) & S32 : 0;
  1007.     UINT32 result = dest << count;
  1008.     CLR_CZS;
  1009.     CHK_XXXL_ZS;    /* set Z and S flags for result long       */
  1010.     if (c) SET_C;
  1011.     return result;
  1012. }
  1013.  
  1014. /******************************************
  1015.  shift right arithmetic byte
  1016.  flags:  CZSV--
  1017.  ******************************************/
  1018. INLINE UINT8 SRAB(UINT8 dest, UINT8 count)
  1019. {
  1020.     UINT8 c = (count) ? ((INT8)dest >> (count - 1)) & 1 : 0;
  1021.     UINT8 result = (UINT8)((INT8)dest >> count);
  1022.     CLR_CZSV;
  1023.     CHK_XXXB_ZS;    /* set Z and S flags for result byte       */
  1024.     if (c) SET_C;
  1025.     return result;
  1026. }
  1027.  
  1028. /******************************************
  1029.  shift right arithmetic word
  1030.  flags:  CZSV--
  1031.  ******************************************/
  1032. INLINE UINT16 SRAW(UINT16 dest, UINT8 count)
  1033. {
  1034.     UINT8 c = (count) ? ((INT16)dest >> (count - 1)) & 1 : 0;
  1035.     UINT16 result = (UINT16)((INT16)dest >> count);
  1036.     CLR_CZSV;
  1037.     CHK_XXXW_ZS;    /* set Z and S flags for result word       */
  1038.     if (c) SET_C;
  1039.     return result;
  1040. }
  1041.  
  1042. /******************************************
  1043.  shift right arithmetic long
  1044.  flags:  CZSV--
  1045.  ******************************************/
  1046. INLINE UINT32 SRAL(UINT32 dest, UINT8 count)
  1047. {
  1048.     UINT8 c = (count) ? ((INT32)dest >> (count - 1)) & 1 : 0;
  1049.     UINT32 result = (UINT32)((INT32)dest >> count);
  1050.     CLR_CZSV;
  1051.     CHK_XXXL_ZS;    /* set Z and S flags for result long       */
  1052.     if (c) SET_C;
  1053.     return result;
  1054. }
  1055.  
  1056. /******************************************
  1057.  shift right logic byte
  1058.  flags:  CZSV--
  1059.  ******************************************/
  1060. INLINE UINT8 SRLB(UINT8 dest, UINT8 count)
  1061. {
  1062.     UINT8 c = (count) ? (dest >> (count - 1)) & 1 : 0;
  1063.     UINT8 result = dest >> count;
  1064.     CLR_CZS;
  1065.     CHK_XXXB_ZS;    /* set Z and S flags for result byte       */
  1066.     if (c) SET_C;
  1067.     return result;
  1068. }
  1069.  
  1070. /******************************************
  1071.  shift right logic word
  1072.  flags:  CZSV--
  1073.  ******************************************/
  1074. INLINE UINT16 SRLW(UINT16 dest, UINT8 count)
  1075. {
  1076.     UINT8 c = (count) ? (dest >> (count - 1)) & 1 : 0;
  1077.     UINT16 result = dest >> count;
  1078.     CLR_CZS;
  1079.     CHK_XXXW_ZS;    /* set Z and S flags for result word       */
  1080.     if (c) SET_C;
  1081.     return result;
  1082. }
  1083.  
  1084. /******************************************
  1085.  shift right logic long
  1086.  flags:  CZSV--
  1087.  ******************************************/
  1088. INLINE UINT32 SRLL(UINT32 dest, UINT8 count)
  1089. {
  1090.     UINT8 c = (count) ? (dest >> (count - 1)) & 1 : 0;
  1091.     UINT32 result = dest >> count;
  1092.     CLR_CZS;
  1093.     CHK_XXXL_ZS;    /* set Z and S flags for result long       */
  1094.     if (c) SET_C;
  1095.     return result;
  1096. }
  1097.  
  1098. /******************************************
  1099.  invalid
  1100.  flags:  ------
  1101.  ******************************************/
  1102. static void  zinvalid(void)
  1103. {
  1104.     logerror("Z8000 invalid opcode %04x: %04x\n", PC, Z.op[0]);
  1105. }
  1106.  
  1107. /******************************************
  1108.  addb     rbd,imm8
  1109.  flags:  CZSVDH
  1110.  ******************************************/
  1111. static void  Z00_0000_dddd_imm8(void)
  1112. {
  1113.     GET_DST(OP0,NIB3);
  1114.     GET_IMM8(OP1);
  1115.     RB(dst) = ADDB( RB(dst), imm8);
  1116. }
  1117.  
  1118. /******************************************
  1119.  addb     rbd,@rs
  1120.  flags:  CZSVDH
  1121.  ******************************************/
  1122. static void Z00_ssN0_dddd(void)
  1123. {
  1124.     GET_DST(OP0,NIB3);
  1125.     GET_SRC(OP0,NIB2);
  1126.     RB(dst) = ADDB( RB(dst), RDMEM_B(RW(src)) );
  1127. }
  1128.  
  1129. /******************************************
  1130.  add     rd,imm16
  1131.  flags:  CZSV--
  1132.  ******************************************/
  1133. static void Z01_0000_dddd_imm16(void)
  1134. {
  1135.     GET_DST(OP0,NIB3);
  1136.     GET_IMM16(OP1);
  1137.     RW(dst) = ADDW( RW(dst), imm16 );
  1138. }
  1139.  
  1140. /******************************************
  1141.  add     rd,@rs
  1142.  flags:  CZSV--
  1143.  ******************************************/
  1144. static void Z01_ssN0_dddd(void)
  1145. {
  1146.     GET_DST(OP0,NIB3);
  1147.     GET_SRC(OP0,NIB2);
  1148.     RW(dst) = ADDW( RW(dst), RDMEM_W(RW(src)) );
  1149. }
  1150.  
  1151. /******************************************
  1152.  subb     rbd,imm8
  1153.  flags:  CZSVDH
  1154.  ******************************************/
  1155. static void Z02_0000_dddd_imm8(void)
  1156. {
  1157.     GET_DST(OP0,NIB3);
  1158.     GET_IMM8(OP1);
  1159.     RB(dst) = SUBB( RB(dst), imm8 );
  1160. }
  1161.  
  1162. /******************************************
  1163.  subb     rbd,@rs
  1164.  flags:  CZSVDH
  1165.  ******************************************/
  1166. static void Z02_ssN0_dddd(void)
  1167. {
  1168.     GET_DST(OP0,NIB3);
  1169.     GET_SRC(OP0,NIB2);
  1170.     RB(dst) = SUBB( RB(dst), RDMEM_B(RW(src)) ); /* EHC */
  1171. }
  1172.  
  1173. /******************************************
  1174.  sub     rd,imm16
  1175.  flags:  CZSV--
  1176.  ******************************************/
  1177. static void Z03_0000_dddd_imm16(void)
  1178. {
  1179.     GET_DST(OP0,NIB3);
  1180.     GET_IMM16(OP1);
  1181.     RW(dst) = SUBW( RW(dst), imm16 );
  1182. }
  1183.  
  1184. /******************************************
  1185.  sub     rd,@rs
  1186.  flags:  CZSV--
  1187.  ******************************************/
  1188. static void Z03_ssN0_dddd(void)
  1189. {
  1190.     GET_DST(OP0,NIB3);
  1191.     GET_SRC(OP0,NIB2);
  1192.     RW(dst) = SUBW( RW(dst), RDMEM_W(RW(src)) );
  1193. }
  1194.  
  1195. /******************************************
  1196.  orb     rbd,imm8
  1197.  flags:  CZSP--
  1198.  ******************************************/
  1199. static void Z04_0000_dddd_imm8(void)
  1200. {
  1201.     GET_DST(OP0,NIB3);
  1202.     GET_IMM8(OP1);
  1203.     RB(dst) = ORB( RB(dst), imm8 );
  1204. }
  1205.  
  1206. /******************************************
  1207.  orb     rbd,@rs
  1208.  flags:  CZSP--
  1209.  ******************************************/
  1210. static void Z04_ssN0_dddd(void)
  1211. {
  1212.     GET_DST(OP0,NIB3);
  1213.     GET_SRC(OP0,NIB2);
  1214.     RB(dst) = ORB( RB(dst), RDMEM_B(RW(src)) );
  1215. }
  1216.  
  1217. /******************************************
  1218.  or      rd,imm16
  1219.  flags:  CZS---
  1220.  ******************************************/
  1221. static void Z05_0000_dddd_imm16(void)
  1222. {
  1223.     GET_DST(OP0,NIB3);
  1224.     GET_IMM16(OP1);
  1225.     RW(dst) = ORW( RW(dst), imm16 );
  1226. }
  1227.  
  1228. /******************************************
  1229.  or      rd,@rs
  1230.  flags:  CZS---
  1231.  ******************************************/
  1232. static void Z05_ssN0_dddd(void)
  1233. {
  1234.     GET_DST(OP0,NIB3);
  1235.     GET_SRC(OP0,NIB2);
  1236.     RW(dst) = ORW( RW(dst), RDMEM_W(RW(src)) );
  1237. }
  1238.  
  1239. /******************************************
  1240.  andb     rbd,imm8
  1241.  flags:  -ZSP--
  1242.  ******************************************/
  1243. static void Z06_0000_dddd_imm8(void)
  1244. {
  1245.     GET_DST(OP0,NIB3);
  1246.     GET_IMM8(OP1);
  1247.     RB(dst) = ANDB( RB(dst), imm8 );
  1248. }
  1249.  
  1250. /******************************************
  1251.  andb     rbd,@rs
  1252.  flags:  -ZSP--
  1253.  ******************************************/
  1254. static void Z06_ssN0_dddd(void)
  1255. {
  1256.     GET_DST(OP0,NIB3);
  1257.     GET_SRC(OP0,NIB2);
  1258.     RB(dst) = ANDB( RB(dst), RDMEM_B(RW(src)) );
  1259. }
  1260.  
  1261. /******************************************
  1262.  and     rd,imm16
  1263.  flags:  -ZS---
  1264.  ******************************************/
  1265. static void Z07_0000_dddd_imm16(void)
  1266. {
  1267.     GET_DST(OP0,NIB3);
  1268.     GET_IMM16(OP1);
  1269.     RW(dst) = ANDW( RW(dst), imm16 );
  1270. }
  1271.  
  1272. /******************************************
  1273.  and     rd,@rs
  1274.  flags:  -ZS---
  1275.  ******************************************/
  1276. static void Z07_ssN0_dddd(void)
  1277. {
  1278.     GET_DST(OP0,NIB3);
  1279.     GET_SRC(OP0,NIB2);
  1280.     RW(dst) = ANDW( RW(dst), RDMEM_W(RW(src)) );
  1281. }
  1282.  
  1283. /******************************************
  1284.  xorb     rbd,imm8
  1285.  flags:  -ZSP--
  1286.  ******************************************/
  1287. static void Z08_0000_dddd_imm8(void)
  1288. {
  1289.     GET_DST(OP0,NIB3);
  1290.     GET_IMM8(OP1);
  1291.     RB(dst) = XORB(RB(dst), imm8);
  1292. }
  1293.  
  1294. /******************************************
  1295.  xorb     rbd,@rs
  1296.  flags:  -ZSP--
  1297.  ******************************************/
  1298. static void Z08_ssN0_dddd(void)
  1299. {
  1300.     GET_DST(OP0,NIB3);
  1301.     GET_SRC(OP0,NIB2);
  1302.     RB(dst) = XORB( RB(dst), RDMEM_B(RW(src)) );
  1303. }
  1304.  
  1305. /******************************************
  1306.  xor     rd,imm16
  1307.  flags:  -ZS---
  1308.  ******************************************/
  1309. static void Z09_0000_dddd_imm16(void)
  1310. {
  1311.     GET_DST(OP0,NIB3);
  1312.     GET_IMM16(OP1);
  1313.     RW(dst) = XORW( RW(dst), imm16 );
  1314. }
  1315.  
  1316. /******************************************
  1317.  xor     rd,@rs
  1318.  flags:  -ZS---
  1319.  ******************************************/
  1320. static void Z09_ssN0_dddd(void)
  1321. {
  1322.     GET_DST(OP0,NIB3);
  1323.     GET_SRC(OP0,NIB2);
  1324.     RW(dst) = XORW( RW(dst), RDMEM_W(RW(src)) );
  1325. }
  1326.  
  1327. /******************************************
  1328.  cpb     rbd,imm8
  1329.  flags:  CZSV--
  1330.  ******************************************/
  1331. static void Z0A_0000_dddd_imm8(void)
  1332. {
  1333.     GET_DST(OP0,NIB3);
  1334.     GET_IMM8(OP1);
  1335.     CPB(RB(dst), imm8);
  1336. }
  1337.  
  1338. /******************************************
  1339.  cpb     rbd,@rs
  1340.  flags:  CZSV--
  1341.  ******************************************/
  1342. static void Z0A_ssN0_dddd(void)
  1343. {
  1344.     GET_DST(OP0,NIB3);
  1345.     GET_SRC(OP0,NIB2);
  1346.     CPB( RB(dst), RDMEM_B(RW(src)) );
  1347. }
  1348.  
  1349. /******************************************
  1350.  cp      rd,imm16
  1351.  flags:  CZSV--
  1352.  ******************************************/
  1353. static void Z0B_0000_dddd_imm16(void)
  1354. {
  1355.     GET_DST(OP0,NIB3);
  1356.     GET_IMM16(OP1);
  1357.     CPW( RW(dst), imm16 );
  1358. }
  1359.  
  1360. /******************************************
  1361.  cp      rd,@rs
  1362.  flags:  CZSV--
  1363.  ******************************************/
  1364. static void Z0B_ssN0_dddd(void)
  1365. {
  1366.     GET_DST(OP0,NIB3);
  1367.     GET_SRC(OP0,NIB2);
  1368.     CPW( RW(dst), RDMEM_W(RW(src)) );
  1369. }
  1370.  
  1371. /******************************************
  1372.  comb     @rd
  1373.  flags:  -ZSP--
  1374.  ******************************************/
  1375. static void Z0C_ddN0_0000(void)
  1376. {
  1377.     GET_DST(OP0,NIB3);
  1378.     WRMEM_B( RW(dst), COMB(RDMEM_B(RW(dst))) );
  1379. }
  1380.  
  1381. /******************************************
  1382.  cpb     @rd,imm8
  1383.  flags:  CZSV--
  1384.  ******************************************/
  1385. static void Z0C_ddN0_0001_imm8(void)
  1386. {
  1387.     GET_DST(OP0,NIB2);
  1388.     GET_IMM8(OP1);
  1389.     CPB( RB(dst), imm8 );
  1390. }
  1391.  
  1392. /******************************************
  1393.  negb     @rd
  1394.  flags:  CZSV--
  1395.  ******************************************/
  1396. static void Z0C_ddN0_0010(void)
  1397. {
  1398.     GET_DST(OP0,NIB2);
  1399.     WRMEM_B( RW(dst), NEGB(RDMEM_B(RW(dst))) );
  1400. }
  1401.  
  1402. /******************************************
  1403.  testb     @rd
  1404.  flags:  -ZSP--
  1405.  ******************************************/
  1406. static void Z0C_ddN0_0100(void)
  1407. {
  1408.     GET_DST(OP0,NIB2);
  1409.     TESTB(RDMEM_B(RW(dst)));
  1410. }
  1411.  
  1412. /******************************************
  1413.  ldb     @rd,imm8
  1414.  flags:  ------
  1415.  ******************************************/
  1416. static void Z0C_ddN0_0101_imm8(void)
  1417. {
  1418.     GET_DST(OP0,NIB2);
  1419.     GET_IMM8(OP1);
  1420.     WRMEM_B( RW(dst), imm8 );
  1421. }
  1422.  
  1423. /******************************************
  1424.  tsetb     @rd
  1425.  flags:  --S---
  1426.  ******************************************/
  1427. static void Z0C_ddN0_0110(void)
  1428. {
  1429.     GET_DST(OP0,NIB2);
  1430.     if (RDMEM_B(RW(dst)) & S08) SET_S; else CLR_S;
  1431.     WRMEM_B(RW(dst), 0xff);
  1432. }
  1433.  
  1434. /******************************************
  1435.  clrb     @rd
  1436.  flags:  ------
  1437.  ******************************************/
  1438. static void Z0C_ddN0_1000(void)
  1439. {
  1440.     GET_DST(OP0,NIB2);
  1441.     WRMEM_B( RW(dst), 0 );
  1442. }
  1443.  
  1444. /******************************************
  1445.  com     @rd
  1446.  flags:  -ZS---
  1447.  ******************************************/
  1448. static void Z0D_ddN0_0000(void)
  1449. {
  1450.     GET_DST(OP0,NIB2);
  1451.     WRMEM_W( RW(dst), COMW(RDMEM_W(RW(dst))) );
  1452. }
  1453.  
  1454. /******************************************
  1455.  cp      @rd,imm16
  1456.  flags:  CZSV--
  1457.  ******************************************/
  1458. static void Z0D_ddN0_0001_imm16(void)
  1459. {
  1460.     GET_DST(OP0,NIB2);
  1461.     GET_IMM16(OP1);
  1462.     CPW( RDMEM_W(RW(dst)), imm16 );
  1463. }
  1464.  
  1465. /******************************************
  1466.  neg     @rd
  1467.  flags:  CZSV--
  1468.  ******************************************/
  1469. static void Z0D_ddN0_0010(void)
  1470. {
  1471.     GET_DST(OP0,NIB2);
  1472.     WRMEM_W( RW(dst), NEGW(RDMEM_W(RW(dst))) );
  1473. }
  1474.  
  1475. /******************************************
  1476.  test     @rd
  1477.  flags:  -ZS---
  1478.  ******************************************/
  1479. static void Z0D_ddN0_0100(void)
  1480. {
  1481.     GET_DST(OP0,NIB2);
  1482.     TESTW( RDMEM_W(RW(dst)) );
  1483. }
  1484.  
  1485. /******************************************
  1486.  ld      @rd,imm16
  1487.  flags:  ------
  1488.  ******************************************/
  1489. static void Z0D_ddN0_0101_imm16(void)
  1490. {
  1491.     GET_DST(OP0,NIB2);
  1492.     GET_IMM16(OP1);
  1493.     WRMEM_W( RW(dst), imm16);
  1494. }
  1495.  
  1496. /******************************************
  1497.  tset     @rd
  1498.  flags:  --S---
  1499.  ******************************************/
  1500. static void Z0D_ddN0_0110(void)
  1501. {
  1502.     GET_DST(OP0,NIB2);
  1503.     if (RDMEM_W(RW(dst)) & S16) SET_S; else CLR_S;
  1504.     WRMEM_W(RW(dst), 0xffff);
  1505. }
  1506.  
  1507. /******************************************
  1508.  clr     @rd
  1509.  flags:  ------
  1510.  ******************************************/
  1511. static void Z0D_ddN0_1000(void)
  1512. {
  1513.     GET_DST(OP0,NIB2);
  1514.     WRMEM_W( RDMEM_W(RW(dst)), 0 );
  1515. }
  1516.  
  1517. /******************************************
  1518.  push     @rd,imm16
  1519.  flags:  ------
  1520.  ******************************************/
  1521. static void Z0D_ddN0_1001_imm16(void)
  1522. {
  1523.     GET_DST(OP0,NIB2);
  1524.     GET_IMM16(OP1);
  1525.     PUSHW( dst, imm16 );
  1526. }
  1527.  
  1528. /******************************************
  1529.  ext0e     imm8
  1530.  flags:  ------
  1531.  ******************************************/
  1532. static void Z0E_imm8(void)
  1533. {
  1534.     GET_IMM8(0);
  1535.     LOG(("Z8K#%d %04x: ext0e  $%02x\n", cpu_getactivecpu(), PC, imm8));
  1536.     if (FCW & F_EPU) {
  1537.         /* Z8001 EPU code goes here */
  1538.         (void)imm8;
  1539.     }
  1540. }
  1541.  
  1542. /******************************************
  1543.  ext0f     imm8
  1544.  flags:  ------
  1545.  ******************************************/
  1546. static void Z0F_imm8(void)
  1547. {
  1548.     GET_IMM8(0);
  1549.     LOG(("Z8K#%d %04x: ext0f  $%02x\n", cpu_getactivecpu(), PC, imm8));
  1550.     if (FCW & F_EPU) {
  1551.         /* Z8001 EPU code goes here */
  1552.         (void)imm8;
  1553.     }
  1554. }
  1555.  
  1556. /******************************************
  1557.  cpl     rrd,imm32
  1558.  flags:  CZSV--
  1559.  ******************************************/
  1560. static void Z10_0000_dddd_imm32(void)
  1561. {
  1562.     GET_DST(OP0,NIB3);
  1563.     GET_IMM32;
  1564.     CPL( RL(dst), imm32 );
  1565. }
  1566.  
  1567. /******************************************
  1568.  cpl     rrd,@rs
  1569.  flags:  CZSV--
  1570.  ******************************************/
  1571. static void Z10_ssN0_dddd(void)
  1572. {
  1573.     GET_DST(OP0,NIB3);
  1574.     GET_SRC(OP0,NIB2);
  1575.     CPL( RL(dst), RDMEM_L(RW(src)) );
  1576. }
  1577.  
  1578. /******************************************
  1579.  pushl     @rd,@rs
  1580.  flags:  ------
  1581.  ******************************************/
  1582. static void Z11_ddN0_ssN0(void)
  1583. {
  1584.     GET_SRC(OP0,NIB3);
  1585.     GET_DST(OP0,NIB2);
  1586.     PUSHL( dst, RDMEM_L(RW(src)) );
  1587. }
  1588.  
  1589. /******************************************
  1590.  subl     rrd,imm32
  1591.  flags:  CZSV--
  1592.  ******************************************/
  1593. static void Z12_0000_dddd_imm32(void)
  1594. {
  1595.     GET_DST(OP0,NIB3);
  1596.     GET_IMM32;
  1597.     RL(dst) = SUBL( RL(dst), imm32 );
  1598. }
  1599.  
  1600. /******************************************
  1601.  subl     rrd,@rs
  1602.  flags:  CZSV--
  1603.  ******************************************/
  1604. static void Z12_ssN0_dddd(void)
  1605. {
  1606.     GET_DST(OP0,NIB3);
  1607.     GET_SRC(OP0,NIB2);
  1608.     RL(dst) = SUBL( RL(dst), RDMEM_L(RW(src)) );
  1609. }
  1610.  
  1611. /******************************************
  1612.  push     @rd,@rs
  1613.  flags:  ------
  1614.  ******************************************/
  1615. static void Z13_ddN0_ssN0(void)
  1616. {
  1617.     GET_SRC(OP0,NIB3);
  1618.     GET_DST(OP0,NIB2);
  1619.     PUSHW( dst, RDMEM_W(RW(src)) );
  1620. }
  1621.  
  1622. /******************************************
  1623.  ldl     rrd,imm32
  1624.  flags:  ------
  1625.  ******************************************/
  1626. static void Z14_0000_dddd_imm32(void)
  1627. {
  1628.     GET_DST(OP0,NIB3);
  1629.     GET_IMM32;
  1630.     RL(dst) = imm32;
  1631. }
  1632.  
  1633. /******************************************
  1634.  ldl     rrd,@rs
  1635.  flags:  ------
  1636.  ******************************************/
  1637. static void Z14_ssN0_dddd(void)
  1638. {
  1639.     GET_DST(OP0,NIB3);
  1640.     GET_SRC(OP0,NIB2);
  1641.     RL(dst) = RDMEM_L( RW(src) );
  1642. }
  1643.  
  1644. /******************************************
  1645.  popl     @rd,@rs
  1646.  flags:  ------
  1647.  ******************************************/
  1648. static void Z15_ssN0_ddN0(void)
  1649. {
  1650.     GET_DST(OP0,NIB3);
  1651.     GET_SRC(OP0,NIB2);
  1652.     RL(dst) = POPL( src );
  1653. }
  1654.  
  1655. /******************************************
  1656.  addl     rrd,imm32
  1657.  flags:  CZSV--
  1658.  ******************************************/
  1659. static void Z16_0000_dddd_imm32(void)
  1660. {
  1661.     GET_DST(OP0,NIB3);
  1662.     GET_IMM32;
  1663.     RL(dst) = ADDL( RL(dst), imm32 );
  1664. }
  1665.  
  1666. /******************************************
  1667.  addl     rrd,@rs
  1668.  flags:  CZSV--
  1669.  ******************************************/
  1670. static void Z16_ssN0_dddd(void)
  1671. {
  1672.     GET_DST(OP0,NIB3);
  1673.     GET_SRC(OP0,NIB2);
  1674.     RL(dst) = ADDL( RL(dst), RDMEM_L(RW(src)) );
  1675. }
  1676.  
  1677. /******************************************
  1678.  pop     @rd,@rs
  1679.  flags:  ------
  1680.  ******************************************/
  1681. static void Z17_ssN0_ddN0(void)
  1682. {
  1683.     GET_DST(OP0,NIB3);
  1684.     GET_SRC(OP0,NIB2);
  1685.     RW(dst) = POPW( src );
  1686. }
  1687.  
  1688. /******************************************
  1689.  multl     rqd,@rs
  1690.  flags:  CZSV--
  1691.  ******************************************/
  1692. static void Z18_ssN0_dddd(void)
  1693. {
  1694.     GET_DST(OP0,NIB3);
  1695.     GET_SRC(OP0,NIB2);
  1696.     RQ(dst) = MULTL( RQ(dst), RL(src) );
  1697. }
  1698.  
  1699. /******************************************
  1700.  mult     rrd,imm16
  1701.  flags:  CZSV--
  1702.  ******************************************/
  1703. static void Z19_0000_dddd_imm16(void)
  1704. {
  1705.     GET_DST(OP0,NIB3);
  1706.     GET_IMM16(OP1);
  1707.     RL(dst) = MULTW( RL(dst), imm16 );
  1708. }
  1709.  
  1710. /******************************************
  1711.  mult     rrd,@rs
  1712.  flags:  CZSV--
  1713.  ******************************************/
  1714. static void Z19_ssN0_dddd(void)
  1715. {
  1716.     GET_DST(OP0,NIB3);
  1717.     GET_SRC(OP0,NIB2);
  1718.     RL(dst) = MULTW( RL(dst), RDMEM_W(RW(src)) );
  1719. }
  1720.  
  1721. /******************************************
  1722.  divl     rqd,imm32
  1723.  flags:  CZSV--
  1724.  ******************************************/
  1725. static void Z1A_0000_dddd_imm32(void)
  1726. {
  1727.     GET_DST(OP0,NIB3);
  1728.     GET_IMM32;
  1729.     RQ(dst) = DIVL( RQ(dst), imm32 );
  1730. }
  1731.  
  1732. /******************************************
  1733.  divl     rqd,@rs
  1734.  flags:  CZSV--
  1735.  ******************************************/
  1736. static void Z1A_ssN0_dddd(void)
  1737. {
  1738.     GET_DST(OP0,NIB3);
  1739.     GET_SRC(OP0,NIB2);
  1740.     RQ(dst) = DIVL( RQ(dst), RDMEM_L(RW(src)) );
  1741. }
  1742.  
  1743. /******************************************
  1744.  div     rrd,imm16
  1745.  flags:  CZSV--
  1746.  ******************************************/
  1747. static void Z1B_0000_dddd_imm16(void)
  1748. {
  1749.     GET_DST(OP0,NIB3);
  1750.     GET_IMM16(OP1);
  1751.     RL(dst) = DIVW( RL(dst), imm16 );
  1752. }
  1753.  
  1754. /******************************************
  1755.  div     rrd,@rs
  1756.  flags:  CZSV--
  1757.  ******************************************/
  1758. static void Z1B_ssN0_dddd(void)
  1759. {
  1760.     GET_DST(OP0,NIB3);
  1761.     GET_SRC(OP0,NIB2);
  1762.     RL(dst) = DIVW( RL(dst), RDMEM_W(RW(src)) );
  1763. }
  1764.  
  1765. /******************************************
  1766.  testl     @rd
  1767.  flags:  -ZS---
  1768.  ******************************************/
  1769. static void Z1C_ddN0_1000(void)
  1770. {
  1771.     GET_DST(OP0,NIB2);
  1772.     TESTL( RDMEM_L(RW(dst)) );
  1773. }
  1774.  
  1775. /******************************************
  1776.  ldm     @rd,rs,n
  1777.  flags:  ------
  1778.  ******************************************/
  1779. static void Z1C_ddN0_1001_0000_ssss_0000_nmin1(void)
  1780. {
  1781.     GET_DST(OP0,NIB2);
  1782.     GET_CNT(OP1,NIB3);
  1783.     GET_SRC(OP1,NIB1);
  1784.     UINT16 idx = RW(dst);
  1785.     while (cnt-- >= 0) {
  1786.         WRMEM_W( idx, RW(src) );
  1787.         idx = (idx + 2) & 0xffff;
  1788.         src = ++src & 15;
  1789.     }
  1790. }
  1791.  
  1792. /******************************************
  1793.  ldm     rd,@rs,n
  1794.  flags:  ------
  1795.  ******************************************/
  1796. static void Z1C_ssN0_0001_0000_dddd_0000_nmin1(void)
  1797. {
  1798.     GET_SRC(OP0,NIB2);
  1799.     GET_CNT(OP1,NIB3);
  1800.     GET_DST(OP1,NIB1);
  1801.     UINT16 idx = RW(src);
  1802.     while (cnt-- >= 0) {
  1803.         RW(dst) = RDMEM_W( idx );
  1804.         idx = (idx + 2) & 0xffff;
  1805.         dst = ++dst & 15;
  1806.     }
  1807. }
  1808.  
  1809. /******************************************
  1810.  ldl     @rd,rrs
  1811.  flags:  ------
  1812.  ******************************************/
  1813. static void Z1D_ddN0_ssss(void)
  1814. {
  1815.     GET_SRC(OP0,NIB3);
  1816.     GET_DST(OP0,NIB2);
  1817.     WRMEM_L( RW(dst), RL(src) );
  1818. }
  1819.  
  1820. /******************************************
  1821.  jp      cc,rd
  1822.  flags:  ------
  1823.  ******************************************/
  1824. static void Z1E_ddN0_cccc(void)
  1825. {
  1826.     GET_CCC(OP0,NIB3);
  1827.     GET_DST(OP0,NIB2);
  1828.     switch (cc) {
  1829.         case  0: if (CC0) PC = RW(dst); break;
  1830.         case  1: if (CC1) PC = RW(dst); break;
  1831.         case  2: if (CC2) PC = RW(dst); break;
  1832.         case  3: if (CC3) PC = RW(dst); break;
  1833.         case  4: if (CC4) PC = RW(dst); break;
  1834.         case  5: if (CC5) PC = RW(dst); break;
  1835.         case  6: if (CC6) PC = RW(dst); break;
  1836.         case  7: if (CC7) PC = RW(dst); break;
  1837.         case  8: if (CC8) PC = RW(dst); break;
  1838.         case  9: if (CC9) PC = RW(dst); break;
  1839.         case 10: if (CCA) PC = RW(dst); break;
  1840.         case 11: if (CCB) PC = RW(dst); break;
  1841.         case 12: if (CCC) PC = RW(dst); break;
  1842.         case 13: if (CCD) PC = RW(dst); break;
  1843.         case 14: if (CCE) PC = RW(dst); break;
  1844.         case 15: if (CCF) PC = RW(dst); break;
  1845.     }
  1846.     change_pc16bew(PC);
  1847. }
  1848.  
  1849. /******************************************
  1850.  call     @rd
  1851.  flags:  ------
  1852.  ******************************************/
  1853. static void Z1F_ddN0_0000(void)
  1854. {
  1855.     GET_DST(OP0,NIB2);
  1856.     PUSHW( SP, PC );
  1857.     PC = RW(dst);
  1858.     change_pc16bew(PC);
  1859. }
  1860.  
  1861. /******************************************
  1862.  ldb     rbd,@rs
  1863.  flags:  ------
  1864.  ******************************************/
  1865. static void Z20_ssN0_dddd(void)
  1866. {
  1867.     GET_DST(OP0,NIB3);
  1868.     GET_SRC(OP0,NIB2);
  1869.     RB(dst) = RDMEM_B( RW(src) );
  1870. }
  1871.  
  1872. /******************************************
  1873.  ld      rd,imm16
  1874.  flags:  ------
  1875.  ******************************************/
  1876. static void Z21_0000_dddd_imm16(void)
  1877. {
  1878.     GET_DST(OP0,NIB3);
  1879.     GET_IMM16(OP1);
  1880.     RW(dst) = imm16;
  1881. }
  1882.  
  1883. /******************************************
  1884.  ld      rd,@rs
  1885.  flags:  ------
  1886.  ******************************************/
  1887. static void Z21_ssN0_dddd(void)
  1888. {
  1889.     GET_DST(OP0,NIB3);
  1890.     GET_SRC(OP0,NIB2);
  1891.     RW(dst) = RDMEM_W( RW(src) );
  1892. }
  1893.  
  1894. /******************************************
  1895.  resb     rbd,rs
  1896.  flags:  ------
  1897.  ******************************************/
  1898. static void Z22_0000_ssss_0000_dddd_0000_0000(void)
  1899. {
  1900.     GET_SRC(OP0,NIB3);
  1901.     GET_DST(OP1,NIB1);
  1902.     RB(dst) = RB(dst) & ~(1 << (RW(src) & 7));
  1903. }
  1904.  
  1905. /******************************************
  1906.  resb     @rd,imm4
  1907.  flags:  ------
  1908.  ******************************************/
  1909. static void Z22_ddN0_imm4(void)
  1910. {
  1911.     GET_BIT(OP0);
  1912.     GET_DST(OP0,NIB2);
  1913.     WRMEM_B(RW(dst), RDMEM_B(RW(dst)) & ~bit);
  1914. }
  1915.  
  1916. /******************************************
  1917.  result     rd,rs
  1918.  flags:  ------
  1919.  ******************************************/
  1920. static void Z23_0000_ssss_0000_dddd_0000_0000(void)
  1921. {
  1922.     GET_SRC(OP0,NIB3);
  1923.     GET_DST(OP1,NIB1);
  1924.     RW(dst) = RW(dst) & ~(1 << (RW(src) & 15));
  1925. }
  1926.  
  1927. /******************************************
  1928.  res     @rd,imm4
  1929.  flags:  ------
  1930.  ******************************************/
  1931. static void Z23_ddN0_imm4(void)
  1932. {
  1933.     GET_BIT(OP0);
  1934.     GET_DST(OP0,NIB2);
  1935.     WRMEM_W(RW(dst), RDMEM_W(RW(dst)) & ~bit);
  1936. }
  1937.  
  1938. /******************************************
  1939.  setb     rbd,rs
  1940.  flags:  ------
  1941.  ******************************************/
  1942. static void Z24_0000_ssss_0000_dddd_0000_0000(void)
  1943. {
  1944.     GET_SRC(OP0,NIB3);
  1945.     GET_DST(OP1,NIB1);
  1946.     RB(dst) = RB(dst) | (1 << (RW(src) & 7));
  1947. }
  1948.  
  1949. /******************************************
  1950.  setb     @rd,imm4
  1951.  flags:  ------
  1952.  ******************************************/
  1953. static void Z24_ddN0_imm4(void)
  1954. {
  1955.     GET_BIT(OP0);
  1956.     GET_DST(OP0,NIB2);
  1957.     WRMEM_B(RW(dst), RDMEM_B(RW(dst)) | bit);
  1958. }
  1959.  
  1960. /******************************************
  1961.  set     rd,rs
  1962.  flags:  ------
  1963.  ******************************************/
  1964. static void Z25_0000_ssss_0000_dddd_0000_0000(void)
  1965. {
  1966.     GET_SRC(OP0,NIB3);
  1967.     GET_DST(OP1,NIB1);
  1968.     RW(dst) = RW(dst) | (1 << (RW(src) & 15));
  1969. }
  1970.  
  1971. /******************************************
  1972.  set     @rd,imm4
  1973.  flags:  ------
  1974.  ******************************************/
  1975. static void Z25_ddN0_imm4(void)
  1976. {
  1977.     GET_BIT(OP0);
  1978.     GET_DST(OP0,NIB2);
  1979.     WRMEM_W(RW(dst), RDMEM_W(RW(dst)) | bit);
  1980. }
  1981.  
  1982. /******************************************
  1983.  bitb     rbd,rs
  1984.  flags:  -Z----
  1985.  ******************************************/
  1986. static void Z26_0000_ssss_0000_dddd_0000_0000(void)
  1987. {
  1988.     GET_SRC(OP0,NIB3);
  1989.     GET_DST(OP1,NIB1);
  1990.     if (RB(dst) & (1 << (RW(src) & 7))) CLR_Z; else SET_Z;
  1991. }
  1992.  
  1993. /******************************************
  1994.  bitb     @rd,imm4
  1995.  flags:  -Z----
  1996.  ******************************************/
  1997. static void Z26_ddN0_imm4(void)
  1998. {
  1999.     GET_BIT(OP0);
  2000.     GET_DST(OP0,NIB2);
  2001.     if (RDMEM_B(RW(dst)) & bit) CLR_Z; else SET_Z;
  2002. }
  2003.  
  2004. /******************************************
  2005.  bit     rd,rs
  2006.  flags:  -Z----
  2007.  ******************************************/
  2008. static void Z27_0000_ssss_0000_dddd_0000_0000(void)
  2009. {
  2010.     GET_SRC(OP0,NIB3);
  2011.     GET_DST(OP1,NIB1);
  2012.     if (RW(dst) & (1 << (RW(src) & 15))) CLR_Z; else SET_Z;
  2013. }
  2014.  
  2015. /******************************************
  2016.  bit     @rd,imm4
  2017.  flags:  -Z----
  2018.  ******************************************/
  2019. static void Z27_ddN0_imm4(void)
  2020. {
  2021.     GET_BIT(OP0);
  2022.     GET_DST(OP0,NIB2);
  2023.     if (RDMEM_W(RW(dst)) & bit) CLR_Z; else SET_Z;
  2024. }
  2025.  
  2026. /******************************************
  2027.  incb     @rd,imm4m1
  2028.  flags:  -ZSV--
  2029.  ******************************************/
  2030. static void Z28_ddN0_imm4m1(void)
  2031. {
  2032.     GET_I4M1(OP0,NIB3);
  2033.     GET_DST(OP0,NIB2);
  2034.     WRMEM_B( RW(dst), INCB( RDMEM_B(RW(dst)), i4p1) );
  2035. }
  2036.  
  2037. /******************************************
  2038.  inc     @rd,imm4m1
  2039.  flags:  -ZSV--
  2040.  ******************************************/
  2041. static void Z29_ddN0_imm4m1(void)
  2042. {
  2043.     GET_I4M1(OP0,NIB3);
  2044.     GET_DST(OP0,NIB2);
  2045.     WRMEM_W( RW(dst), INCW( RDMEM_W(RW(dst)), i4p1 ) );
  2046. }
  2047.  
  2048. /******************************************
  2049.  decb     @rd,imm4m1
  2050.  flags:  -ZSV--
  2051.  ******************************************/
  2052. static void Z2A_ddN0_imm4m1(void)
  2053. {
  2054.     GET_I4M1(OP0,NIB3);
  2055.     GET_DST(OP0,NIB2);
  2056.     WRMEM_B( RW(dst), DECB( RDMEM_B(RW(dst)), i4p1 ) );
  2057. }
  2058.  
  2059. /******************************************
  2060.  dec     @rd,imm4m1
  2061.  flags:  -ZSV--
  2062.  ******************************************/
  2063. static void Z2B_ddN0_imm4m1(void)
  2064. {
  2065.     GET_I4M1(OP0,NIB3);
  2066.     GET_DST(OP0,NIB2);
  2067.     WRMEM_W( RW(dst), DECW( RDMEM_W(RW(dst)), i4p1 ) );
  2068. }
  2069.  
  2070. /******************************************
  2071.  exb     rbd,@rs
  2072.  flags:  ------
  2073.  ******************************************/
  2074. static void Z2C_ssN0_dddd(void)
  2075. {
  2076.     GET_DST(OP0,NIB3);
  2077.     GET_SRC(OP0,NIB2);
  2078.     UINT8 tmp = RDMEM_B( RW(src) );
  2079.     WRMEM_B( RW(src), RB(dst) );
  2080.     RB(dst) = tmp;
  2081. }
  2082.  
  2083. /******************************************
  2084.  ex      rd,@rs
  2085.  flags:  ------
  2086.  ******************************************/
  2087. static void Z2D_ssN0_dddd(void)
  2088. {
  2089.     GET_DST(OP0,NIB3);
  2090.     GET_SRC(OP0,NIB2);
  2091.     UINT16 tmp = RDMEM_W( RW(src) );
  2092.     WRMEM_W( RW(src), RW(dst) );
  2093.     RW(dst) = tmp;
  2094. }
  2095.  
  2096. /******************************************
  2097.  ldb     @rd,rbs
  2098.  flags:  ------
  2099.  ******************************************/
  2100. static void Z2E_ddN0_ssss(void)
  2101. {
  2102.     GET_SRC(OP0,NIB3);
  2103.     GET_DST(OP0,NIB2);
  2104.     WRMEM_B( RW(dst), RB(src) );
  2105. }
  2106.  
  2107. /******************************************
  2108.  ld      @rd,rs
  2109.  flags:  ------
  2110.  ******************************************/
  2111. static void Z2F_ddN0_ssss(void)
  2112. {
  2113.     GET_SRC(OP0,NIB3);
  2114.     GET_DST(OP0,NIB2);
  2115.     WRMEM_W( RW(dst), RW(src) );
  2116. }
  2117.  
  2118. /******************************************
  2119.  ldrb     rbd,dsp16
  2120.  flags:  ------
  2121.  ******************************************/
  2122. static void Z30_0000_dddd_dsp16(void)
  2123. {
  2124.     GET_DST(OP0,NIB3);
  2125.     GET_DSP16;
  2126.     RB(dst) = RDMEM_B(dsp16);
  2127. }
  2128.  
  2129. /******************************************
  2130.  ldb     rbd,rs(imm16)
  2131.  flags:  ------
  2132.  ******************************************/
  2133. static void Z30_ssN0_dddd_imm16(void)
  2134. {
  2135.     GET_DST(OP0,NIB3);
  2136.     GET_SRC(OP0,NIB2);
  2137.     GET_IMM16(OP1);
  2138.     imm16 += RW(src);
  2139.     RB(dst) = RDMEM_B( imm16 );
  2140. }
  2141.  
  2142. /******************************************
  2143.  ldr     rd,dsp16
  2144.  flags:  ------
  2145.  ******************************************/
  2146. static void Z31_0000_dddd_dsp16(void)
  2147. {
  2148.     GET_DST(OP0,NIB3);
  2149.     GET_DSP16;
  2150.     RW(dst) = RDMEM_W(dsp16);
  2151. }
  2152.  
  2153. /******************************************
  2154.  ld      rd,rs(imm16)
  2155.  flags:  ------
  2156.  ******************************************/
  2157. static void Z31_ssN0_dddd_imm16(void)
  2158. {
  2159.     GET_DST(OP0,NIB3);
  2160.     GET_SRC(OP0,NIB2);
  2161.     GET_IMM16(OP1);
  2162.     imm16 += RW(src);
  2163.     RW(dst) = RDMEM_W( imm16 );
  2164. }
  2165.  
  2166. /******************************************
  2167.  ldrb     dsp16,rbs
  2168.  flags:  ------
  2169.  ******************************************/
  2170. static void Z32_0000_ssss_dsp16(void)
  2171. {
  2172.     GET_SRC(OP0,NIB3);
  2173.     GET_DSP16;
  2174.     WRMEM_B( dsp16, RB(src) );
  2175. }
  2176.  
  2177. /******************************************
  2178.  ldb     rd(imm16),rbs
  2179.  flags:  ------
  2180.  ******************************************/
  2181. static void Z32_ddN0_ssss_imm16(void)
  2182. {
  2183.     GET_SRC(OP0,NIB3);
  2184.     GET_DST(OP0,NIB2);
  2185.     GET_IMM16(OP1);
  2186.     imm16 += RW(dst);
  2187.     WRMEM_B( imm16, RB(src) );
  2188. }
  2189.  
  2190. /******************************************
  2191.  ldr     dsp16,rs
  2192.  flags:  ------
  2193.  ******************************************/
  2194. static void Z33_0000_ssss_dsp16(void)
  2195. {
  2196.     GET_SRC(OP0,NIB3);
  2197.     GET_DSP16;
  2198.     WRMEM_W( dsp16, RW(src) );
  2199. }
  2200.  
  2201. /******************************************
  2202.  ld      rd(imm16),rs
  2203.  flags:  ------
  2204.  ******************************************/
  2205. static void Z33_ddN0_ssss_imm16(void)
  2206. {
  2207.     GET_SRC(OP0,NIB3);
  2208.     GET_DST(OP0,NIB2);
  2209.     GET_IMM16(OP1);
  2210.     imm16 += RW(dst);
  2211.     WRMEM_W( imm16, RW(src) );
  2212. }
  2213.  
  2214. /******************************************
  2215.  ldar     prd,dsp16
  2216.  flags:  ------
  2217.  ******************************************/
  2218. static void Z34_0000_dddd_dsp16(void)
  2219. {
  2220.     GET_DST(OP0,NIB3);
  2221.     GET_DSP16;
  2222.     RW(dst) = dsp16;
  2223. }
  2224.  
  2225. /******************************************
  2226.  lda     prd,rs(imm16)
  2227.  flags:  ------
  2228.  ******************************************/
  2229. static void Z34_ssN0_dddd_imm16(void)
  2230. {
  2231.     GET_DST(OP0,NIB3);
  2232.     GET_SRC(OP0,NIB2);
  2233.     GET_IMM16(OP1);
  2234.     imm16 += RW(src);
  2235.     RW(dst) = imm16;
  2236. }
  2237.  
  2238. /******************************************
  2239.  ldrl     rrd,dsp16
  2240.  flags:  ------
  2241.  ******************************************/
  2242. static void Z35_0000_dddd_dsp16(void)
  2243. {
  2244.     GET_DST(OP0,NIB3);
  2245.     GET_DSP16;
  2246.     RL(dst) = RDMEM_L( dsp16 );
  2247. }
  2248.  
  2249. /******************************************
  2250.  ldl     rrd,rs(imm16)
  2251.  flags:  ------
  2252.  ******************************************/
  2253. static void Z35_ssN0_dddd_imm16(void)
  2254. {
  2255.     GET_DST(OP0,NIB3);
  2256.     GET_SRC(OP0,NIB2);
  2257.     GET_IMM16(OP1);
  2258.     imm16 += RW(src);
  2259.     RL(dst) = RDMEM_L( imm16 );
  2260. }
  2261.  
  2262. /******************************************
  2263.  bpt
  2264.  flags:  ------
  2265.  ******************************************/
  2266. static void Z36_0000_0000(void)
  2267. {
  2268.     /* execute break point trap IRQ_REQ */
  2269.     IRQ_REQ = Z8000_TRAP;
  2270. }
  2271.  
  2272. /******************************************
  2273.  rsvd36
  2274.  flags:  ------
  2275.  ******************************************/
  2276. static void Z36_imm8(void)
  2277. {
  2278.     GET_IMM8(0);
  2279.     LOG(("Z8K#%d %04x: rsvd36 $%02x\n", cpu_getactivecpu(), PC, imm8));
  2280.     if (FCW & F_EPU) {
  2281.         /* Z8001 EPU code goes here */
  2282.         (void)imm8;
  2283.     }
  2284. }
  2285.  
  2286. /******************************************
  2287.  ldrl     dsp16,rrs
  2288.  flags:  ------
  2289.  ******************************************/
  2290. static void Z37_0000_ssss_dsp16(void)
  2291. {
  2292.     GET_SRC(OP0,NIB3);
  2293.     GET_DSP16;
  2294.     WRMEM_L( dsp16, RL(src) );
  2295. }
  2296.  
  2297. /******************************************
  2298.  ldl     rd(imm16),rrs
  2299.  flags:  ------
  2300.  ******************************************/
  2301. static void Z37_ddN0_ssss_imm16(void)
  2302. {
  2303.     GET_SRC(OP0,NIB3);
  2304.     GET_DST(OP0,NIB2);
  2305.     GET_IMM16(OP1);
  2306.     imm16 += RW(dst);
  2307.     WRMEM_L( imm16, RL(src) );
  2308. }
  2309.  
  2310. /******************************************
  2311.  rsvd38
  2312.  flags:  ------
  2313.  ******************************************/
  2314. static void Z38_imm8(void)
  2315. {
  2316.     GET_IMM8(0);
  2317.     LOG(("Z8K#%d %04x: rsvd38 $%02x\n", cpu_getactivecpu(), PC, imm8));
  2318.     if (FCW & F_EPU) {
  2319.         /* Z8001 EPU code goes here */
  2320.         (void)imm8;
  2321.     }
  2322. }
  2323.  
  2324. /******************************************
  2325.  ldps     @rs
  2326.  flags:  CZSVDH
  2327.  ******************************************/
  2328. static void Z39_ssN0_0000(void)
  2329. {
  2330.     GET_SRC(OP0,NIB2);
  2331.     UINT16 fcw;
  2332.     fcw = RDMEM_W( RW(src) );
  2333.     PC    = RDMEM_W( (UINT16)(RW(src) + 2) );
  2334.     CHANGE_FCW(fcw); /* check for user/system mode change */
  2335.     change_pc16bew(PC);
  2336. }
  2337.  
  2338. /******************************************
  2339.  inib(r) @rd,@rs,ra
  2340.  flags:  ---V--
  2341.  ******************************************/
  2342. static void Z3A_ssss_0000_0000_aaaa_dddd_x000(void)
  2343. {
  2344.     GET_SRC(OP0,NIB2);
  2345.     GET_CNT(OP1,NIB1);
  2346.     GET_DST(OP1,NIB2);
  2347.     GET_CCC(OP1,NIB3);
  2348.     WRMEM_B( RW(dst), RDPORT_B( 0, RW(src) ) );
  2349.     RW(dst)++;
  2350.     RW(src)++;
  2351.     if (--RW(cnt)) { CLR_V; if (cc == 0) PC -= 4; } else SET_V;
  2352. }
  2353.  
  2354. /******************************************
  2355.  sinib     @rd,@rs,ra
  2356.  sinibr  @rd,@rs,ra
  2357.  flags:  ------
  2358.  ******************************************/
  2359. static void Z3A_ssss_0001_0000_aaaa_dddd_x000(void)
  2360. {
  2361.     GET_SRC(OP0,NIB2);
  2362.     GET_CNT(OP1,NIB1);
  2363.     GET_DST(OP1,NIB2);
  2364.     GET_CCC(OP1,NIB3);
  2365.     WRMEM_B( RW(dst), RDPORT_B( 1, RW(src) ) );
  2366.     RW(dst)++;
  2367.     RW(src)++;
  2368.     if (--RW(cnt)) { CLR_V; if (cc == 0) PC -= 4; } else SET_V;
  2369. }
  2370.  
  2371. /******************************************
  2372.  outib     @rd,@rs,ra
  2373.  outibr  @rd,@rs,ra
  2374.  flags:  ---V--
  2375.  ******************************************/
  2376. static void Z3A_ssss_0010_0000_aaaa_dddd_x000(void)
  2377. {
  2378.     GET_SRC(OP0,NIB2);
  2379.     GET_CNT(OP1,NIB1);
  2380.     GET_DST(OP1,NIB2);
  2381.     GET_CCC(OP1,NIB3);
  2382.     WRPORT_B( 0, RW(dst), RDMEM_B( RW(src) ) );
  2383.     RW(dst)++;
  2384.     RW(src)++;
  2385.     if (--RW(cnt)) { CLR_V; if (cc == 0) PC -= 4; } else SET_V;
  2386. }
  2387.  
  2388. /******************************************
  2389.  soutib  @rd,@rs,ra
  2390.  soutibr @rd,@rs,ra
  2391.  flags:  ------
  2392.  ******************************************/
  2393. static void Z3A_ssss_0011_0000_aaaa_dddd_x000(void)
  2394. {
  2395.     GET_SRC(OP0,NIB2);
  2396.     GET_CNT(OP1,NIB1);
  2397.     GET_DST(OP1,NIB2);
  2398.     GET_CCC(OP1,NIB3);
  2399.     WRPORT_B( 1, RW(dst), RDMEM_B( RW(src) ) );
  2400.     RW(dst)++;
  2401.     RW(src)++;
  2402.     if (--RW(cnt)) { CLR_V; if (cc == 0) PC -= 4; } else SET_V;
  2403. }
  2404.  
  2405. /******************************************
  2406.  inb     rbd,imm16
  2407.  flags:  ------
  2408.  ******************************************/
  2409. static void Z3A_dddd_0100_imm16(void)
  2410. {
  2411.     GET_DST(OP0,NIB2);
  2412.     GET_IMM16(OP1);
  2413.     RB(dst) = RDPORT_B( 0, imm16 );
  2414. }
  2415.  
  2416. /******************************************
  2417.  sinb    rbd,imm16
  2418.  flags:  ------
  2419.  ******************************************/
  2420. static void Z3A_dddd_0101_imm16(void)
  2421. {
  2422.     GET_DST(OP0,NIB2);
  2423.     GET_IMM16(OP1);
  2424.     RB(dst) = RDPORT_B( 1, imm16 );
  2425. }
  2426.  
  2427. /******************************************
  2428.  outb    imm16,rbs
  2429.  flags:  ---V--
  2430.  ******************************************/
  2431. static void Z3A_ssss_0110_imm16(void)
  2432. {
  2433.     GET_SRC(OP0,NIB2);
  2434.     GET_IMM16(OP1);
  2435.     WRPORT_B( 0, imm16, RB(src) );
  2436. }
  2437.  
  2438. /******************************************
  2439.  soutb   imm16,rbs
  2440.  flags:  ------
  2441.  ******************************************/
  2442. static void Z3A_ssss_0111_imm16(void)
  2443. {
  2444.     GET_SRC(OP0,NIB2);
  2445.     GET_IMM16(OP1);
  2446.     WRPORT_B( 1, imm16, RB(src) );
  2447. }
  2448.  
  2449. /******************************************
  2450.  indb     @rd,@rs,rba
  2451.  indbr     @rd,@rs,rba
  2452.  flags:  ---V--
  2453.  ******************************************/
  2454. static void Z3A_ssss_1000_0000_aaaa_dddd_x000(void)
  2455. {
  2456.     GET_SRC(OP0,NIB2);
  2457.     GET_CNT(OP1,NIB1);
  2458.     GET_DST(OP1,NIB2);
  2459.     GET_CCC(OP1,NIB3);
  2460.     WRMEM_B( RW(dst), RDPORT_B( 0, RW(src) ) );
  2461.     RW(dst)--;
  2462.     RW(src)--;
  2463.     if (--RW(cnt)) { CLR_V; if (cc == 0) PC -= 4; } else SET_V;
  2464. }
  2465.  
  2466. /******************************************
  2467.  sindb     @rd,@rs,rba
  2468.  sindbr  @rd,@rs,rba
  2469.  flags:  ------
  2470.  ******************************************/
  2471. static void Z3A_ssss_1001_0000_aaaa_dddd_x000(void)
  2472. {
  2473.     GET_SRC(OP0,NIB2);
  2474.     GET_CNT(OP1,NIB1);
  2475.     GET_DST(OP1,NIB2);
  2476.     GET_CCC(OP1,NIB3);
  2477.     WRMEM_B( RW(dst), RDPORT_B( 1, RW(src) ) );
  2478.     RW(dst)--;
  2479.     RW(src)--;
  2480.     if (--RW(cnt)) { CLR_V; if (cc == 0) PC -= 4; } else SET_V;
  2481. }
  2482.  
  2483. /******************************************
  2484.  outdb     @rd,@rs,rba
  2485.  outdbr  @rd,@rs,rba
  2486.  flags:  ---V--
  2487.  ******************************************/
  2488. static void Z3A_ssss_1010_0000_aaaa_dddd_x000(void)
  2489. {
  2490.     GET_SRC(OP0,NIB2);
  2491.     GET_CNT(OP1,NIB1);
  2492.     GET_DST(OP1,NIB2);
  2493.     GET_CCC(OP1,NIB3);
  2494.     WRPORT_B( 0, RW(dst), RDMEM_B( RW(src) ) );
  2495.     RW(dst)--;
  2496.     RW(src)--;
  2497.     if (--RW(cnt)) { CLR_V; if (cc == 0) PC -= 4; } else SET_V;
  2498. }
  2499.  
  2500. /******************************************
  2501.  soutdb  @rd,@rs,rba
  2502.  soutdbr @rd,@rs,rba
  2503.  flags:  ------
  2504.  ******************************************/
  2505. static void Z3A_ssss_1011_0000_aaaa_dddd_x000(void)
  2506. {
  2507.     GET_SRC(OP0,NIB2);
  2508.     GET_CNT(OP1,NIB1);
  2509.     GET_DST(OP1,NIB2);
  2510.     GET_CCC(OP1,NIB3);
  2511.     WRPORT_B( 1, RW(dst), RDMEM_B( RW(src) ) );
  2512.     RW(dst)--;
  2513.     RW(src)--;
  2514.     if (--RW(cnt)) { CLR_V; if (cc == 0) PC -= 4; } else SET_V;
  2515. }
  2516.  
  2517. /******************************************
  2518.  ini     @rd,@rs,ra
  2519.  inir     @rd,@rs,ra
  2520.  flags:  ---V--
  2521.  ******************************************/
  2522. static void Z3B_ssss_0000_0000_aaaa_dddd_x000(void)
  2523. {
  2524.     GET_SRC(OP0,NIB2);
  2525.     GET_CNT(OP1,NIB1);
  2526.     GET_DST(OP1,NIB2);
  2527.     GET_CCC(OP1,NIB3);
  2528.     WRMEM_W( RW(dst), RDPORT_W( 0, RW(src) ) );
  2529.     RW(dst) += 2;
  2530.     RW(src) += 2;
  2531.     if (--RW(cnt)) { CLR_V; if (cc == 0) PC -= 4; } else SET_V;
  2532. }
  2533.  
  2534. /******************************************
  2535.  sini     @rd,@rs,ra
  2536.  sinir     @rd,@rs,ra
  2537.  flags:  ------
  2538.  ******************************************/
  2539. static void Z3B_ssss_0001_0000_aaaa_dddd_x000(void)
  2540. {
  2541.     GET_SRC(OP0,NIB2);
  2542.     GET_CNT(OP1,NIB1);
  2543.     GET_DST(OP1,NIB2);
  2544.     GET_CCC(OP1,NIB3);
  2545.     WRMEM_W( RW(dst), RDPORT_W( 1, RW(src) ) );
  2546.     RW(dst) += 2;
  2547.     RW(src) += 2;
  2548.     if (--RW(cnt)) { CLR_V; if (cc == 0) PC -= 4; } else SET_V;
  2549. }
  2550.  
  2551. /******************************************
  2552.  outi     @rd,@rs,ra
  2553.  outir     @rd,@rs,ra
  2554.  flags:  ---V--
  2555.  ******************************************/
  2556. static void Z3B_ssss_0010_0000_aaaa_dddd_x000(void)
  2557. {
  2558.     GET_SRC(OP0,NIB2);
  2559.     GET_CNT(OP1,NIB1);
  2560.     GET_DST(OP1,NIB2);
  2561.     GET_CCC(OP1,NIB3);
  2562.     WRPORT_W( 0, RW(dst), RDMEM_W( RW(src) ) );
  2563.     RW(dst) += 2;
  2564.     RW(src) += 2;
  2565.     if (--RW(cnt)) { CLR_V; if (cc == 0) PC -= 4; } else SET_V;
  2566. }
  2567.  
  2568. /******************************************
  2569.  souti     @rd,@rs,ra
  2570.  soutir  @rd,@rs,ra
  2571.  flags:  ------
  2572.  ******************************************/
  2573. static void Z3B_ssss_0011_0000_aaaa_dddd_x000(void)
  2574. {
  2575.     GET_SRC(OP0,NIB2);
  2576.     GET_CNT(OP1,NIB1);
  2577.     GET_DST(OP1,NIB2);
  2578.     GET_CCC(OP1,NIB3);
  2579.     WRPORT_W( 1, RW(dst), RDMEM_W( RW(src) ) );
  2580.     RW(dst) += 2;
  2581.     RW(src) += 2;
  2582.     if (--RW(cnt)) { CLR_V; if (cc == 0) PC -= 4; } else SET_V;
  2583. }
  2584.  
  2585. /******************************************
  2586.  in      rd,imm16
  2587.  flags:  ------
  2588.  ******************************************/
  2589. static void Z3B_dddd_0100_imm16(void)
  2590. {
  2591.     GET_DST(OP0,NIB2);
  2592.     GET_IMM16(OP1);
  2593.     RW(dst) = RDPORT_W( 0, imm16 );
  2594. }
  2595.  
  2596. /******************************************
  2597.  sin     rd,imm16
  2598.  flags:  ------
  2599.  ******************************************/
  2600. static void Z3B_dddd_0101_imm16(void)
  2601. {
  2602.     GET_DST(OP0,NIB2);
  2603.     GET_IMM16(OP1);
  2604.     RW(dst) = RDPORT_W( 1, imm16 );
  2605. }
  2606.  
  2607. /******************************************
  2608.  out     imm16,rs
  2609.  flags:  ---V--
  2610.  ******************************************/
  2611. static void Z3B_ssss_0110_imm16(void)
  2612. {
  2613.     GET_SRC(OP0,NIB2);
  2614.     GET_IMM16(OP1);
  2615.     WRPORT_W( 0, imm16, RW(src) );
  2616. }
  2617.  
  2618. /******************************************
  2619.  sout     imm16,rbs
  2620.  flags:  ------
  2621.  ******************************************/
  2622. static void Z3B_ssss_0111_imm16(void)
  2623. {
  2624.     GET_SRC(OP0,NIB2);
  2625.     GET_IMM16(OP1);
  2626.     WRPORT_W( 1, imm16, RW(src) );
  2627. }
  2628.  
  2629. /******************************************
  2630.  ind     @rd,@rs,ra
  2631.  indr     @rd,@rs,ra
  2632.  flags:  ---V--
  2633.  ******************************************/
  2634. static void Z3B_ssss_1000_0000_aaaa_dddd_x000(void)
  2635. {
  2636.     GET_SRC(OP0,NIB2);
  2637.     GET_CNT(OP1,NIB1);
  2638.     GET_DST(OP1,NIB2);
  2639.     GET_CCC(OP1,NIB3);
  2640.     WRMEM_W( RW(dst), RDPORT_W( 0, RW(src) ) );
  2641.     RW(dst) -= 2;
  2642.     RW(src) -= 2;
  2643.     if (--RW(cnt)) { CLR_V; if (cc == 0) PC -= 4; } else SET_V;
  2644. }
  2645.  
  2646. /******************************************
  2647.  sind     @rd,@rs,ra
  2648.  sindr     @rd,@rs,ra
  2649.  flags:  ------
  2650.  ******************************************/
  2651. static void Z3B_ssss_1001_0000_aaaa_dddd_x000(void)
  2652. {
  2653.     GET_SRC(OP0,NIB2);
  2654.     GET_CNT(OP1,NIB1);
  2655.     GET_DST(OP1,NIB2);
  2656.     GET_CCC(OP1,NIB3);
  2657.     WRMEM_W( RW(dst), RDPORT_W( 1, RW(src) ) );
  2658.     RW(dst) -= 2;
  2659.     RW(src) -= 2;
  2660.     if (--RW(cnt)) { CLR_V; if (cc == 0) PC -= 4; } else SET_V;
  2661. }
  2662.  
  2663. /******************************************
  2664.  outd     @rd,@rs,ra
  2665.  outdr     @rd,@rs,ra
  2666.  flags:  ---V--
  2667.  ******************************************/
  2668. static void Z3B_ssss_1010_0000_aaaa_dddd_x000(void)
  2669. {
  2670.     GET_SRC(OP0,NIB2);
  2671.     GET_CNT(OP1,NIB1);
  2672.     GET_DST(OP1,NIB2);
  2673.     GET_CCC(OP1,NIB3);
  2674.     WRPORT_W( 0, RW(dst), RDMEM_W( RW(src) ) );
  2675.     RW(dst) -= 2;
  2676.     RW(src) -= 2;
  2677.     if (--RW(cnt)) { CLR_V; if (cc == 0) PC -= 4; } else SET_V;
  2678. }
  2679.  
  2680. /******************************************
  2681.  soutd     @rd,@rs,ra
  2682.  soutdr  @rd,@rs,ra
  2683.  flags:  ------
  2684.  ******************************************/
  2685. static void Z3B_ssss_1011_0000_aaaa_dddd_x000(void)
  2686. {
  2687.     GET_SRC(OP0,NIB2);
  2688.     GET_CNT(OP1,NIB1);
  2689.     GET_DST(OP1,NIB2);
  2690.     GET_CCC(OP1,NIB3);
  2691.     WRPORT_W( 1, RW(dst), RDMEM_W( RW(src) ) );
  2692.     RW(dst) -= 2;
  2693.     RW(src) -= 2;
  2694.     if (--RW(cnt)) { CLR_V; if (cc == 0) PC -= 4; } else SET_V;
  2695. }
  2696.  
  2697. /******************************************
  2698.  inb     rbd,@rs
  2699.  flags:  ------
  2700.  ******************************************/
  2701. static void Z3C_ssss_dddd(void)
  2702. {
  2703.     GET_SRC(OP0,NIB2);
  2704.     GET_DST(OP0,NIB3);
  2705.     RB(dst) = RDPORT_B( 0, RDMEM_W( RW(src) ) );
  2706. }
  2707.  
  2708. /******************************************
  2709.  in      rd,@rs
  2710.  flags:  ------
  2711.  ******************************************/
  2712. static void Z3D_ssss_dddd(void)
  2713. {
  2714.     GET_SRC(OP0,NIB2);
  2715.     GET_DST(OP0,NIB3);
  2716.     RW(dst) = RDPORT_W( 0, RDMEM_W( RW(src) ) );
  2717. }
  2718.  
  2719. /******************************************
  2720.  outb     @rd,rbs
  2721.  flags:  ---V--
  2722.  ******************************************/
  2723. static void Z3E_dddd_ssss(void)
  2724. {
  2725.     GET_DST(OP0,NIB2);
  2726.     GET_SRC(OP0,NIB3);
  2727.     WRPORT_B( 0, RDMEM_W( RW(dst) ), RB(src) );
  2728. }
  2729.  
  2730. /******************************************
  2731.  out     @rd,rs
  2732.  flags:  ---V--
  2733.  ******************************************/
  2734. static void Z3F_dddd_ssss(void)
  2735. {
  2736.     GET_DST(OP0,NIB2);
  2737.     GET_SRC(OP0,NIB3);
  2738.     WRPORT_W( 0, RDMEM_W( RW(dst) ), RW(src) );
  2739. }
  2740.  
  2741. /******************************************
  2742.  addb     rbd,addr
  2743.  flags:  CZSVDH
  2744.  ******************************************/
  2745. static void Z40_0000_dddd_addr(void)
  2746. {
  2747.     GET_DST(OP0,NIB3);
  2748.     GET_ADDR(OP1);
  2749.     RB(dst) = ADDB( RB(dst), RDMEM_B(addr) );
  2750. }
  2751.  
  2752. /******************************************
  2753.  addb     rbd,addr(rs)
  2754.  flags:  CZSVDH
  2755.  ******************************************/
  2756. static void Z40_ssN0_dddd_addr(void)
  2757. {
  2758.     GET_DST(OP0,NIB3);
  2759.     GET_SRC(OP0,NIB2);
  2760.     GET_ADDR(OP1);
  2761.     addr += RW(src);
  2762.     RB(dst) = ADDB( RB(dst), RDMEM_B(addr) );
  2763. }
  2764.  
  2765. /******************************************
  2766.  add     rd,addr
  2767.  flags:  CZSV--
  2768.  ******************************************/
  2769. static void Z41_0000_dddd_addr(void)
  2770. {
  2771.     GET_DST(OP0,NIB3);
  2772.     GET_ADDR(OP1);
  2773.     RW(dst) = ADDW( RW(dst), RDMEM_W(addr)); /* EHC */
  2774. }
  2775.  
  2776. /******************************************
  2777.  add     rd,addr(rs)
  2778.  flags:  CZSV--
  2779.  ******************************************/
  2780. static void Z41_ssN0_dddd_addr(void)
  2781. {
  2782.     GET_DST(OP0,NIB3);
  2783.     GET_SRC(OP0,NIB2);
  2784.     GET_ADDR(OP1);
  2785.     addr += RW(src);
  2786.     RW(dst) = ADDW( RW(dst), RDMEM_W(addr) );    /* ASG */
  2787. }
  2788.  
  2789. /******************************************
  2790.  subb     rbd,addr
  2791.  flags:  CZSVDH
  2792.  ******************************************/
  2793. static void Z42_0000_dddd_addr(void)
  2794. {
  2795.     GET_DST(OP0,NIB3);
  2796.     GET_ADDR(OP1);
  2797.     RB(dst) = SUBB( RB(dst), RDMEM_B(addr)); /* EHC */
  2798. }
  2799.  
  2800. /******************************************
  2801.  subb     rbd,addr(rs)
  2802.  flags:  CZSVDH
  2803.  ******************************************/
  2804. static void Z42_ssN0_dddd_addr(void)
  2805. {
  2806.     GET_DST(OP0,NIB3);
  2807.     GET_SRC(OP0,NIB2);
  2808.     GET_ADDR(OP1);
  2809.     addr += RW(src);
  2810.     RB(dst) = SUBB( RB(dst), RDMEM_B(addr) );
  2811. }
  2812.  
  2813. /******************************************
  2814.  sub     rd,addr
  2815.  flags:  CZSV--
  2816.  ******************************************/
  2817. static void Z43_0000_dddd_addr(void)
  2818. {
  2819.     GET_DST(OP0,NIB3);
  2820.     GET_ADDR(OP1);
  2821.     RW(dst) = SUBW( RW(dst), RDMEM_W(addr) );
  2822. }
  2823.  
  2824. /******************************************
  2825.  sub     rd,addr(rs)
  2826.  flags:  CZSV--
  2827.  ******************************************/
  2828. static void Z43_ssN0_dddd_addr(void)
  2829. {
  2830.     GET_DST(OP0,NIB3);
  2831.     GET_SRC(OP0,NIB2);
  2832.     GET_ADDR(OP1);
  2833.     addr += RW(src);
  2834.     RW(dst) = SUBW( RW(dst), RDMEM_W(addr) );
  2835. }
  2836.  
  2837. /******************************************
  2838.  orb     rbd,addr
  2839.  flags:  CZSP--
  2840.  ******************************************/
  2841. static void Z44_0000_dddd_addr(void)
  2842. {
  2843.     GET_DST(OP0,NIB3);
  2844.     GET_ADDR(OP1);
  2845.     RB(dst) = ORB( RB(dst), RDMEM_B(addr) );
  2846. }
  2847.  
  2848. /******************************************
  2849.  orb     rbd,addr(rs)
  2850.  flags:  CZSP--
  2851.  ******************************************/
  2852. static void Z44_ssN0_dddd_addr(void)
  2853. {
  2854.     GET_DST(OP0,NIB3);
  2855.     GET_SRC(OP0,NIB2);
  2856.     GET_ADDR(OP1);
  2857.     addr += RW(src);
  2858.     RB(dst) = ORB( RB(dst), RDMEM_B(addr) );
  2859. }
  2860.  
  2861. /******************************************
  2862.  or      rd,addr
  2863.  flags:  CZS---
  2864.  ******************************************/
  2865. static void Z45_0000_dddd_addr(void)
  2866. {
  2867.     GET_DST(OP0,NIB3);
  2868.     GET_ADDR(OP1);
  2869.     RW(dst) = ORW( RW(dst), RDMEM_W(addr) );
  2870. }
  2871.  
  2872. /******************************************
  2873.  or      rd,addr(rs)
  2874.  flags:  CZS---
  2875.  ******************************************/
  2876. static void Z45_ssN0_dddd_addr(void)
  2877. {
  2878.     GET_DST(OP0,NIB3);
  2879.     GET_SRC(OP0,NIB2);
  2880.     GET_ADDR(OP1);
  2881.     addr += RW(src);
  2882.     RW(dst) = ORW( RW(dst), RDMEM_W(addr) );
  2883. }
  2884.  
  2885. /******************************************
  2886.  andb     rbd,addr
  2887.  flags:  -ZSP--
  2888.  ******************************************/
  2889. static void Z46_0000_dddd_addr(void)
  2890. {
  2891.     GET_DST(OP0,NIB3);
  2892.     GET_ADDR(OP1);
  2893.     RB(dst) = ANDB( RB(dst), RDMEM_B(addr) );
  2894. }
  2895.  
  2896. /******************************************
  2897.  andb     rbd,addr(rs)
  2898.  flags:  -ZSP--
  2899.  ******************************************/
  2900. static void Z46_ssN0_dddd_addr(void)
  2901. {
  2902.     GET_DST(OP0,NIB3);
  2903.     GET_SRC(OP0,NIB2);
  2904.     GET_ADDR(OP1);
  2905.     addr += RW(src);
  2906.     RB(dst) = ANDB( RB(dst), RDMEM_B(addr) );
  2907. }
  2908.  
  2909. /******************************************
  2910.  and     rd,addr
  2911.  flags:  -ZS---
  2912.  ******************************************/
  2913. static void Z47_0000_dddd_addr(void)
  2914. {
  2915.     GET_DST(OP0,NIB3);
  2916.     GET_ADDR(OP1);
  2917.     RW(dst) = ANDW( RW(dst), RDMEM_W(addr) );
  2918. }
  2919.  
  2920. /******************************************
  2921.  and     rd,addr(rs)
  2922.  flags:  -ZS---
  2923.  ******************************************/
  2924. static void Z47_ssN0_dddd_addr(void)
  2925. {
  2926.     GET_DST(OP0,NIB3);
  2927.     GET_SRC(OP0,NIB2);
  2928.     GET_ADDR(OP1);
  2929.     addr += RW(src);
  2930.     RW(dst) = ANDW( RW(dst), RDMEM_W(addr) );
  2931. }
  2932.  
  2933. /******************************************
  2934.  xorb     rbd,addr
  2935.  flags:  -ZSP--
  2936.  ******************************************/
  2937. static void Z48_0000_dddd_addr(void)
  2938. {
  2939.     GET_DST(OP0,NIB3);
  2940.     GET_ADDR(OP1);
  2941.     RB(dst) = XORB( RB(dst), RDMEM_B(addr) );
  2942. }
  2943.  
  2944. /******************************************
  2945.  xorb     rbd,addr(rs)
  2946.  flags:  -ZSP--
  2947.  ******************************************/
  2948. static void Z48_ssN0_dddd_addr(void)
  2949. {
  2950.     GET_DST(OP0,NIB3);
  2951.     GET_SRC(OP0,NIB2);
  2952.     GET_ADDR(OP1);
  2953.     addr += RW(src);
  2954.     RB(dst) = XORB( RB(dst), RDMEM_B(addr) );
  2955. }
  2956.  
  2957. /******************************************
  2958.  xor     rd,addr
  2959.  flags:  -ZS---
  2960.  ******************************************/
  2961. static void Z49_0000_dddd_addr(void)
  2962. {
  2963.     GET_DST(OP0,NIB3);
  2964.     GET_ADDR(OP1);
  2965.     RW(dst) = XORW( RW(dst), RDMEM_W(addr) );
  2966. }
  2967.  
  2968. /******************************************
  2969.  xor     rd,addr(rs)
  2970.  flags:  -ZS---
  2971.  ******************************************/
  2972. static void Z49_ssN0_dddd_addr(void)
  2973. {
  2974.     GET_DST(OP0,NIB3);
  2975.     GET_SRC(OP0,NIB2);
  2976.     GET_ADDR(OP1);
  2977.     addr += RW(src);
  2978.     RW(dst) = XORW( RW(dst), RDMEM_W(addr) );
  2979. }
  2980.  
  2981. /******************************************
  2982.  cpb     rbd,addr
  2983.  flags:  CZSV--
  2984.  ******************************************/
  2985. static void Z4A_0000_dddd_addr(void)
  2986. {
  2987.     GET_DST(OP0,NIB3);
  2988.     GET_ADDR(OP1);
  2989.     CPB( RB(dst), RDMEM_B(addr) );
  2990. }
  2991.  
  2992. /******************************************
  2993.  cpb     rbd,addr(rs)
  2994.  flags:  CZSV--
  2995.  ******************************************/
  2996. static void Z4A_ssN0_dddd_addr(void)
  2997. {
  2998.     GET_DST(OP0,NIB3);
  2999.     GET_SRC(OP0,NIB2);
  3000.     GET_ADDR(OP1);
  3001.     addr += RW(src);
  3002.     CPB( RB(dst), RDMEM_B(addr) );
  3003. }
  3004.  
  3005. /******************************************
  3006.  cp      rd,addr
  3007.  flags:  CZSV--
  3008.  ******************************************/
  3009. static void Z4B_0000_dddd_addr(void)
  3010. {
  3011.     GET_DST(OP0,NIB3);
  3012.     GET_ADDR(OP1);
  3013.     CPW( RW(dst), RDMEM_W(addr) );
  3014. }
  3015.  
  3016. /******************************************
  3017.  cp      rd,addr(rs)
  3018.  flags:  CZSV--
  3019.  ******************************************/
  3020. static void Z4B_ssN0_dddd_addr(void)
  3021. {
  3022.     GET_DST(OP0,NIB3);
  3023.     GET_SRC(OP0,NIB2);
  3024.     GET_ADDR(OP1);
  3025.     addr += RW(src);
  3026.     CPW( RW(dst), RDMEM_W(addr) );
  3027. }
  3028.  
  3029. /******************************************
  3030.  comb     addr
  3031.  flags:  -ZSP--
  3032.  ******************************************/
  3033. static void Z4C_0000_0000_addr(void)
  3034. {
  3035.     GET_ADDR(OP1);
  3036.     WRMEM_B( addr, COMB(RDMEM_W(addr)) );
  3037. }
  3038.  
  3039. /******************************************
  3040.  cpb     addr,imm8
  3041.  flags:  CZSV--
  3042.  ******************************************/
  3043. static void Z4C_0000_0001_addr_imm8(void)
  3044. {
  3045.     GET_ADDR(OP1);
  3046.     GET_IMM8(OP2);
  3047.     CPB( RDMEM_B(addr), imm8 );
  3048. }
  3049.  
  3050. /******************************************
  3051.  negb     addr
  3052.  flags:  CZSV--
  3053.  ******************************************/
  3054. static void Z4C_0000_0010_addr(void)
  3055. {
  3056.     GET_ADDR(OP1);
  3057.     WRMEM_B( addr, NEGB(RDMEM_B(addr)) );
  3058. }
  3059.  
  3060. /******************************************
  3061.  testb     addr
  3062.  flags:  -ZSP--
  3063.  ******************************************/
  3064. static void Z4C_0000_0100_addr(void)
  3065. {
  3066.     GET_ADDR(OP1);
  3067.     TESTB(RDMEM_B(addr));
  3068. }
  3069.  
  3070. /******************************************
  3071.  ldb     addr,imm8
  3072.  flags:  ------
  3073.  ******************************************/
  3074. static void Z4C_0000_0101_addr_imm8(void)
  3075. {
  3076.     GET_ADDR(OP1);
  3077.     GET_IMM8(OP2);
  3078.     WRMEM_B( addr, imm8 );
  3079. }
  3080.  
  3081. /******************************************
  3082.  tsetb     addr
  3083.  flags:  --S---
  3084.  ******************************************/
  3085. static void Z4C_0000_0110_addr(void)
  3086. {
  3087.     GET_ADDR(OP1);
  3088.     if (RDMEM_B(addr) & S08) SET_S; else CLR_S;
  3089.     WRMEM_B(addr, 0xff);
  3090. }
  3091.  
  3092. /******************************************
  3093.  clrb     addr
  3094.  flags:  ------
  3095.  ******************************************/
  3096. static void Z4C_0000_1000_addr(void)
  3097. {
  3098.     GET_ADDR(OP1);
  3099.     WRMEM_B( addr, 0 );
  3100. }
  3101.  
  3102. /******************************************
  3103.  comb     addr(rd)
  3104.  flags:  -ZSP--
  3105.  ******************************************/
  3106. static void Z4C_ddN0_0000_addr(void)
  3107. {
  3108.     GET_DST(OP0,NIB2);
  3109.     GET_ADDR(OP1);
  3110.     addr += RW(dst);
  3111.     WRMEM_B( addr, COMB(RDMEM_B(addr)) );
  3112. }
  3113.  
  3114. /******************************************
  3115.  cpb     addr(rd),imm8
  3116.  flags:  CZSV--
  3117.  ******************************************/
  3118. static void Z4C_ddN0_0001_addr_imm8(void)
  3119. {
  3120.     GET_DST(OP0,NIB2);
  3121.     GET_ADDR(OP1);
  3122.     GET_IMM8(OP2);
  3123.     addr += RW(dst);
  3124.     CPB( RDMEM_B(addr), imm8 );
  3125. }
  3126.  
  3127. /******************************************
  3128.  negb     addr(rd)
  3129.  flags:  CZSV--
  3130.  ******************************************/
  3131. static void Z4C_ddN0_0010_addr(void)
  3132. {
  3133.     GET_DST(OP0,NIB2);
  3134.     GET_ADDR(OP1);
  3135.     addr += RW(dst);
  3136.     WRMEM_B( addr, NEGB(RDMEM_B(addr)) );
  3137. }
  3138.  
  3139. /******************************************
  3140.  testb     addr(rd)
  3141.  flags:  -ZSP--
  3142.  ******************************************/
  3143. static void Z4C_ddN0_0100_addr(void)
  3144. {
  3145.     GET_DST(OP0,NIB2);
  3146.     GET_ADDR(OP1);
  3147.     addr += RW(dst);
  3148.     TESTB( RDMEM_B(addr) );
  3149. }
  3150.  
  3151. /******************************************
  3152.  ldb     addr(rd),imm8
  3153.  flags:  ------
  3154.  ******************************************/
  3155. static void Z4C_ddN0_0101_addr_imm8(void)
  3156. {
  3157.     GET_DST(OP0,NIB2);
  3158.     GET_ADDR(OP1);
  3159.     GET_IMM8(OP2);
  3160.     addr += RW(dst);
  3161.     WRMEM_B( addr, imm8 );
  3162. }
  3163.  
  3164. /******************************************
  3165.  tsetb     addr(rd)
  3166.  flags:  --S---
  3167.  ******************************************/
  3168. static void Z4C_ddN0_0110_addr(void)
  3169. {
  3170.     GET_DST(OP0,NIB2);
  3171.     GET_ADDR(OP1);
  3172.     addr += RW(dst);
  3173.     if (RDMEM_B(addr) & S08) SET_S; else CLR_S;
  3174.     WRMEM_B(addr, 0xff);
  3175. }
  3176.  
  3177. /******************************************
  3178.  clrb     addr(rd)
  3179.  flags:  ------
  3180.  ******************************************/
  3181. static void Z4C_ddN0_1000_addr(void)
  3182. {
  3183.     GET_DST(OP0,NIB2);
  3184.     GET_ADDR(OP1);
  3185.     addr += RW(dst);
  3186.     WRMEM_B( addr, 0 );
  3187. }
  3188.  
  3189. /******************************************
  3190.  com     addr
  3191.  flags:  -ZS---
  3192.  ******************************************/
  3193. static void Z4D_0000_0000_addr(void)
  3194. {
  3195.     GET_ADDR(OP1);
  3196.     WRMEM_W( addr, COMW(RDMEM_W(addr)) );
  3197. }
  3198.  
  3199. /******************************************
  3200.  cp      addr,imm16
  3201.  flags:  CZSV--
  3202.  ******************************************/
  3203. static void Z4D_0000_0001_addr_imm16(void)
  3204. {
  3205.     GET_ADDR(OP1);
  3206.     GET_IMM16(OP2);
  3207.     CPW( RDMEM_W(addr), imm16 );
  3208. }
  3209.  
  3210. /******************************************
  3211.  neg     addr
  3212.  flags:  CZSV--
  3213.  ******************************************/
  3214. static void Z4D_0000_0010_addr(void)
  3215. {
  3216.     GET_ADDR(OP1);
  3217.     WRMEM_W( addr, NEGW(RDMEM_W(addr)) );
  3218. }
  3219.  
  3220. /******************************************
  3221.  test     addr
  3222.  flags:  ------
  3223.  ******************************************/
  3224. static void Z4D_0000_0100_addr(void)
  3225. {
  3226.     GET_ADDR(OP1);
  3227.     TESTW( RDMEM_W(addr) );
  3228. }
  3229.  
  3230. /******************************************
  3231.  ld      addr,imm16
  3232.  flags:  ------
  3233.  ******************************************/
  3234. static void Z4D_0000_0101_addr_imm16(void)
  3235. {
  3236.     GET_ADDR(OP1);
  3237.     GET_IMM16(OP2);
  3238.     WRMEM_W( addr, imm16 );
  3239. }
  3240.  
  3241. /******************************************
  3242.  tset     addr
  3243.  flags:  --S---
  3244.  ******************************************/
  3245. static void Z4D_0000_0110_addr(void)
  3246. {
  3247.     GET_ADDR(OP1);
  3248.     if (RDMEM_W(addr) & S16) SET_S; else CLR_S;
  3249.     WRMEM_W(addr, 0xffff);
  3250. }
  3251.  
  3252. /******************************************
  3253.  clr     addr
  3254.  flags:  ------
  3255.  ******************************************/
  3256. static void Z4D_0000_1000_addr(void)
  3257. {
  3258.     GET_ADDR(OP1);
  3259.     WRMEM_W( addr, 0 );
  3260. }
  3261.  
  3262. /******************************************
  3263.  com     addr(rd)
  3264.  flags:  -ZS---
  3265.  ******************************************/
  3266. static void Z4D_ddN0_0000_addr(void)
  3267. {
  3268.     GET_DST(OP0,NIB2);
  3269.     GET_ADDR(OP1);
  3270.     addr += RW(dst);
  3271.     WRMEM_W( addr, COMW(RDMEM_W(addr)) );
  3272. }
  3273.  
  3274. /******************************************
  3275.  cp      addr(rd),imm16
  3276.  flags:  CZSV--
  3277.  ******************************************/
  3278. static void Z4D_ddN0_0001_addr_imm16(void)
  3279. {
  3280.     GET_DST(OP0,NIB2);
  3281.     GET_ADDR(OP1);
  3282.     GET_IMM16(OP2);
  3283.     addr += RW(dst);
  3284.     CPW( RDMEM_W(addr), imm16 );
  3285. }
  3286.  
  3287. /******************************************
  3288.  neg     addr(rd)
  3289.  flags:  CZSV--
  3290.  ******************************************/
  3291. static void Z4D_ddN0_0010_addr(void)
  3292. {
  3293.     GET_DST(OP0,NIB2);
  3294.     GET_ADDR(OP1);
  3295.     addr += RW(dst);
  3296.     WRMEM_W( addr, NEGW(RDMEM_W(addr)) );
  3297. }
  3298.  
  3299. /******************************************
  3300.  test     addr(rd)
  3301.  flags:  ------
  3302.  ******************************************/
  3303. static void Z4D_ddN0_0100_addr(void)
  3304. {
  3305.     GET_DST(OP0,NIB2);
  3306.     GET_ADDR(OP1);
  3307.     addr += RW(dst);
  3308.     TESTW( RDMEM_W(addr) );
  3309. }
  3310.  
  3311. /******************************************
  3312.  ld      addr(rd),imm16
  3313.  flags:  ------
  3314.  ******************************************/
  3315. static void Z4D_ddN0_0101_addr_imm16(void)
  3316. {
  3317.     GET_DST(OP0,NIB2);
  3318.     GET_ADDR(OP1);
  3319.     GET_IMM16(OP2);
  3320.     addr += RW(dst);
  3321.     WRMEM_W( addr, imm16 );
  3322. }
  3323.  
  3324. /******************************************
  3325.  tset     addr(rd)
  3326.  flags:  --S---
  3327.  ******************************************/
  3328. static void Z4D_ddN0_0110_addr(void)
  3329. {
  3330.     GET_DST(OP0,NIB2);
  3331.     GET_ADDR(OP1);
  3332.     addr += RW(dst);
  3333.     if (RDMEM_W(addr) & S16) SET_S; else CLR_S;
  3334.     WRMEM_W(addr, 0xffff);
  3335. }
  3336.  
  3337. /******************************************
  3338.  clr     addr(rd)
  3339.  flags:  ------
  3340.  ******************************************/
  3341. static void Z4D_ddN0_1000_addr(void)
  3342. {
  3343.     GET_DST(OP0,NIB2);
  3344.     GET_ADDR(OP1);
  3345.     addr += RW(dst);
  3346.     WRMEM_W( addr, 0 );
  3347. }
  3348.  
  3349. /******************************************
  3350.  ldb     addr(rd),rbs
  3351.  flags:  ------
  3352.  ******************************************/
  3353. static void Z4E_ddN0_ssN0_addr(void)
  3354. {
  3355.     GET_DST(OP0,NIB2);
  3356.     GET_SRC(OP0,NIB3);
  3357.     GET_ADDR(OP1);
  3358.     addr += RW(dst);
  3359.     WRMEM_B( addr, RB(src) );
  3360. }
  3361.  
  3362. /******************************************
  3363.  cpl     rrd,addr
  3364.  flags:  CZSV--
  3365.  ******************************************/
  3366. static void Z50_0000_dddd_addr(void)
  3367. {
  3368.     GET_DST(OP0,NIB3);
  3369.     GET_ADDR(OP1);
  3370.     CPL( RL(dst), RDMEM_L(addr) );
  3371. }
  3372.  
  3373. /******************************************
  3374.  cpl     rrd,addr(rs)
  3375.  flags:  CZSV--
  3376.  ******************************************/
  3377. static void Z50_ssN0_dddd_addr(void)
  3378. {
  3379.     GET_DST(OP0,NIB3);
  3380.     GET_SRC(OP0,NIB2);
  3381.     GET_ADDR(OP1);
  3382.     addr += RW(src);
  3383.     CPL( RL(dst), RDMEM_L(addr) );
  3384. }
  3385.  
  3386. /******************************************
  3387.  pushl     @rd,addr
  3388.  flags:  ------
  3389.  ******************************************/
  3390. static void Z51_ddN0_0000_addr(void)
  3391. {
  3392.     GET_DST(OP0,NIB2);
  3393.     GET_ADDR(OP1);
  3394.     PUSHL( dst, RDMEM_L(addr) );
  3395. }
  3396.  
  3397. /******************************************
  3398.  pushl     @rd,addr(rs)
  3399.  flags:  ------
  3400.  ******************************************/
  3401. static void Z51_ddN0_ssN0_addr(void)
  3402. {
  3403.     GET_SRC(OP0,NIB3);
  3404.     GET_DST(OP0,NIB2);
  3405.     GET_ADDR(OP1);
  3406.     addr += RW(src);
  3407.     PUSHL( dst, RDMEM_L(addr) );
  3408. }
  3409.  
  3410. /******************************************
  3411.  subl     rrd,addr
  3412.  flags:  CZSV--
  3413.  ******************************************/
  3414. static void Z52_0000_dddd_addr(void)
  3415. {
  3416.     GET_DST(OP0,NIB3);
  3417.     GET_ADDR(OP1);
  3418.     RL(dst) = SUBL( RL(dst), RDMEM_L(addr) );
  3419. }
  3420.  
  3421. /******************************************
  3422.  subl     rrd,addr(rs)
  3423.  flags:  CZSV--
  3424.  ******************************************/
  3425. static void Z52_ssN0_dddd_addr(void)
  3426. {
  3427.     GET_DST(OP0,NIB3);
  3428.     GET_SRC(OP0,NIB2);
  3429.     GET_ADDR(OP1);
  3430.     addr += RW(src);
  3431.     RL(dst) = SUBL( RL(dst), RDMEM_L(addr) );
  3432. }
  3433.  
  3434. /******************************************
  3435.  push     @rd,addr
  3436.  flags:  ------
  3437.  ******************************************/
  3438. static void Z53_ddN0_0000_addr(void)
  3439. {
  3440.     GET_DST(OP0,NIB2);
  3441.     GET_ADDR(OP1);
  3442.     PUSHW( dst, RDMEM_W(addr) );
  3443. }
  3444.  
  3445. /******************************************
  3446.  push     @rd,addr(rs)
  3447.  flags:  ------
  3448.  ******************************************/
  3449. static void Z53_ddN0_ssN0_addr(void)
  3450. {
  3451.     GET_DST(OP0,NIB2);
  3452.     GET_SRC(OP0,NIB3);
  3453.     GET_ADDR(OP1);
  3454.     addr += RW(src);
  3455.     PUSHW( dst, RDMEM_W(addr) );
  3456. }
  3457.  
  3458. /******************************************
  3459.  ldl     rrd,addr
  3460.  flags:  ------
  3461.  ******************************************/
  3462. static void Z54_0000_dddd_addr(void)
  3463. {
  3464.     GET_DST(OP0,NIB3);
  3465.     GET_ADDR(OP1);
  3466.     RL(dst) = RDMEM_L( addr );
  3467. }
  3468.  
  3469. /******************************************
  3470.  ldl     rrd,addr(rs)
  3471.  flags:  ------
  3472.  ******************************************/
  3473. static void Z54_ssN0_dddd_addr(void)
  3474. {
  3475.     GET_DST(OP0,NIB3);
  3476.     GET_SRC(OP0,NIB2);
  3477.     GET_ADDR(OP1);
  3478.     addr += RW(src);
  3479.     RL(dst) = RDMEM_L( addr );
  3480. }
  3481.  
  3482. /******************************************
  3483.  popl     addr,@rs
  3484.  flags:  ------
  3485.  ******************************************/
  3486. static void Z55_ssN0_0000_addr(void)
  3487. {
  3488.     GET_SRC(OP0,NIB2);
  3489.     GET_ADDR(OP1);
  3490.     WRMEM_L( addr, POPL(src) );
  3491. }
  3492.  
  3493. /******************************************
  3494.  popl     addr(rd),@rs
  3495.  flags:  ------
  3496.  ******************************************/
  3497. static void Z55_ssN0_ddN0_addr(void)
  3498. {
  3499.     GET_DST(OP0,NIB3);
  3500.     GET_SRC(OP0,NIB2);
  3501.     GET_ADDR(OP1);
  3502.     addr += RW(dst);
  3503.     WRMEM_L( addr, POPL(src) );
  3504. }
  3505.  
  3506. /******************************************
  3507.  addl     rrd,addr
  3508.  flags:  CZSV--
  3509.  ******************************************/
  3510. static void Z56_0000_dddd_addr(void)
  3511. {
  3512.     GET_DST(OP0,NIB3);
  3513.     GET_ADDR(OP1);
  3514.     RL(dst) = ADDL( RL(dst), RDMEM_L(addr) );
  3515. }
  3516.  
  3517. /******************************************
  3518.  addl     rrd,addr(rs)
  3519.  flags:  CZSV--
  3520.  ******************************************/
  3521. static void Z56_ssN0_dddd_addr(void)
  3522. {
  3523.     GET_DST(OP0,NIB3);
  3524.     GET_SRC(OP0,NIB2);
  3525.     GET_ADDR(OP1);
  3526.     addr += RW(src);
  3527.     RL(dst) = ADDL( RL(dst), RDMEM_L(addr) );
  3528. }
  3529.  
  3530. /******************************************
  3531.  pop     addr,@rs
  3532.  flags:  ------
  3533.  ******************************************/
  3534. static void Z57_ssN0_0000_addr(void)
  3535. {
  3536.     GET_SRC(OP0,NIB2);
  3537.     GET_ADDR(OP1);
  3538.     WRMEM_W( addr, POPW(src) );
  3539. }
  3540.  
  3541. /******************************************
  3542.  pop     addr(rd),@rs
  3543.  flags:  ------
  3544.  ******************************************/
  3545. static void Z57_ssN0_ddN0_addr(void)
  3546. {
  3547.     GET_DST(OP0,NIB3);
  3548.     GET_SRC(OP0,NIB2);
  3549.     GET_ADDR(OP1);
  3550.     addr += RW(dst);
  3551.     WRMEM_W( addr, POPW(src) );
  3552. }
  3553.  
  3554. /******************************************
  3555.  multl     rqd,addr
  3556.  flags:  CZSV--
  3557.  ******************************************/
  3558. static void Z58_0000_dddd_addr(void)
  3559. {
  3560.     GET_DST(OP0,NIB3);
  3561.     GET_ADDR(OP1);
  3562.     RQ(dst) = MULTL( RQ(dst), RDMEM_L(addr) );
  3563. }
  3564.  
  3565. /******************************************
  3566.  multl     rqd,addr(rs)
  3567.  flags:  CZSV--
  3568.  ******************************************/
  3569. static void Z58_ssN0_dddd_addr(void)
  3570. {
  3571.     GET_DST(OP0,NIB3);
  3572.     GET_SRC(OP0,NIB2);
  3573.     GET_ADDR(OP1);
  3574.     addr += RW(src);
  3575.     RQ(dst) = MULTL( RQ(dst), RDMEM_L(addr) );
  3576. }
  3577.  
  3578. /******************************************
  3579.  mult     rrd,addr
  3580.  flags:  CZSV--
  3581.  ******************************************/
  3582. static void Z59_0000_dddd_addr(void)
  3583. {
  3584.     GET_DST(OP0,NIB3);
  3585.     GET_ADDR(OP1);
  3586.     RL(dst) = MULTW( RL(dst), RDMEM_W(addr) );
  3587. }
  3588.  
  3589. /******************************************
  3590.  mult     rrd,addr(rs)
  3591.  flags:  CZSV--
  3592.  ******************************************/
  3593. static void Z59_ssN0_dddd_addr(void)
  3594. {
  3595.     GET_DST(OP0,NIB3);
  3596.     GET_SRC(OP0,NIB2);
  3597.     GET_ADDR(OP1);
  3598.     addr += RW(src);
  3599.     RL(dst) = MULTW( RL(dst), RDMEM_W(addr) );
  3600. }
  3601.  
  3602. /******************************************
  3603.  divl     rqd,addr
  3604.  flags:  CZSV--
  3605.  ******************************************/
  3606. static void Z5A_0000_dddd_addr(void)
  3607. {
  3608.     GET_DST(OP0,NIB3);
  3609.     GET_ADDR(OP1);
  3610.     RQ(dst) = DIVL( RQ(dst), RDMEM_L(addr) );
  3611. }
  3612.  
  3613. /******************************************
  3614.  divl     rqd,addr(rs)
  3615.  flags:  CZSV--
  3616.  ******************************************/
  3617. static void Z5A_ssN0_dddd_addr(void)
  3618. {
  3619.     GET_DST(OP0,NIB3);
  3620.     GET_SRC(OP0,NIB2);
  3621.     GET_ADDR(OP1);
  3622.     addr += RW(src);
  3623.     RQ(dst) = DIVL( RQ(dst), RDMEM_L(addr) );
  3624. }
  3625.  
  3626. /******************************************
  3627.  div     rrd,addr
  3628.  flags:  CZSV--
  3629.  ******************************************/
  3630. static void Z5B_0000_dddd_addr(void)
  3631. {
  3632.     GET_DST(OP0,NIB3);
  3633.     GET_ADDR(OP1);
  3634.     RL(dst) = DIVW( RL(dst), RDMEM_W(addr) );
  3635. }
  3636.  
  3637. /******************************************
  3638.  div     rrd,addr(rs)
  3639.  flags:  CZSV--
  3640.  ******************************************/
  3641. static void Z5B_ssN0_dddd_addr(void)
  3642. {
  3643.     GET_DST(OP0,NIB3);
  3644.     GET_SRC(OP0,NIB2);
  3645.     GET_ADDR(OP1);
  3646.     addr += RW(src);
  3647.     RL(dst) = DIVW( RL(dst), RDMEM_W(addr) );
  3648. }
  3649.  
  3650. /******************************************
  3651.  ldm     rd,addr,n
  3652.  flags:  ------
  3653.  ******************************************/
  3654. static void Z5C_0000_0001_0000_dddd_0000_nmin1_addr(void)
  3655. {
  3656.     GET_DST(OP1,NIB1);
  3657.     GET_CNT(OP1,NIB3);
  3658.     GET_ADDR(OP2);
  3659.     while (cnt-- >= 0) {
  3660.         RW(dst) = RDMEM_W(addr);
  3661.         dst = ++dst & 15;
  3662.         addr = (addr + 2) & 0xffff;
  3663.     }
  3664. }
  3665.  
  3666. /******************************************
  3667.  testl     addr
  3668.  flags:  -ZS---
  3669.  ******************************************/
  3670. static void Z5C_0000_1000_addr(void)
  3671. {
  3672.     GET_ADDR(OP1);
  3673.     TESTL( RDMEM_L(addr) );
  3674. }
  3675.  
  3676. /******************************************
  3677.  ldm     addr,rs,n
  3678.  flags:  ------
  3679.  ******************************************/
  3680. static void Z5C_0000_1001_0000_ssss_0000_nmin1_addr(void)
  3681. {
  3682.     GET_SRC(OP1,NIB1);
  3683.     GET_CNT(OP1,NIB3);
  3684.     GET_ADDR(OP2);
  3685.     while (cnt-- >= 0) {
  3686.         WRMEM_W( addr, RW(src) );
  3687.         src = ++src & 15;
  3688.         addr = (addr + 2) & 0xffff;
  3689.     }
  3690. }
  3691.  
  3692. /******************************************
  3693.  testl     addr(rd)
  3694.  flags:  -ZS---
  3695.  ******************************************/
  3696. static void Z5C_ddN0_1000_addr(void)
  3697. {
  3698.     GET_DST(OP0,NIB2);
  3699.     GET_ADDR(OP1);
  3700.     addr += RW(dst);
  3701.     TESTL( RDMEM_L(addr) );
  3702. }
  3703.  
  3704. /******************************************
  3705.  ldm     addr(rd),rs,n
  3706.  flags:  ------
  3707.  ******************************************/
  3708. static void Z5C_ddN0_1001_0000_ssN0_0000_nmin1_addr(void)
  3709. {
  3710.     GET_DST(OP0,NIB2);
  3711.     GET_SRC(OP1,NIB1);
  3712.     GET_CNT(OP1,NIB3);
  3713.     GET_ADDR(OP2);
  3714.     addr += RW(dst);
  3715.     while (cnt-- >= 0) {
  3716.         WRMEM_W( addr, RW(src) );
  3717.         src = ++src & 15;
  3718.         addr = (addr + 2) & 0xffff;
  3719.     }
  3720. }
  3721.  
  3722. /******************************************
  3723.  ldm     rd,addr(rs),n
  3724.  flags:  ------
  3725.  ******************************************/
  3726. static void Z5C_ssN0_0001_0000_dddd_0000_nmin1_addr(void)
  3727. {
  3728.     GET_SRC(OP0,NIB2);
  3729.     GET_DST(OP1,NIB1);
  3730.     GET_CNT(OP1,NIB3);
  3731.     GET_ADDR(OP2);
  3732.     addr += RW(src);
  3733.     while (cnt-- >= 0) {
  3734.         RW(dst) = RDMEM_W(addr);
  3735.         dst = ++dst & 15;
  3736.         addr = (addr + 2) & 0xffff;
  3737.     }
  3738. }
  3739.  
  3740. /******************************************
  3741.  ldl     addr,rrs
  3742.  flags:  ------
  3743.  ******************************************/
  3744. static void Z5D_0000_ssss_addr(void)
  3745. {
  3746.     GET_SRC(OP0,NIB3);
  3747.     GET_ADDR(OP1);
  3748.     WRMEM_L( addr, RL(src) );
  3749. }
  3750.  
  3751. /******************************************
  3752.  ldl     addr(rd),rrs
  3753.  flags:  ------
  3754.  ******************************************/
  3755. static void Z5D_ddN0_ssss_addr(void)
  3756. {
  3757.     GET_SRC(OP0,NIB3);
  3758.     GET_DST(OP0,NIB2);
  3759.     GET_ADDR(OP1);
  3760.     addr += RW(dst);
  3761.     WRMEM_L( addr, RL(src) );
  3762. }
  3763.  
  3764. /******************************************
  3765.  jp      cc,addr
  3766.  flags:  ------
  3767.  ******************************************/
  3768. static void Z5E_0000_cccc_addr(void)
  3769. {
  3770.     GET_CCC(OP0,NIB3);
  3771.     GET_ADDR(OP1);
  3772.     switch (cc) {
  3773.         case  0: if (CC0) PC = addr; break;
  3774.         case  1: if (CC1) PC = addr; break;
  3775.         case  2: if (CC2) PC = addr; break;
  3776.         case  3: if (CC3) PC = addr; break;
  3777.         case  4: if (CC4) PC = addr; break;
  3778.         case  5: if (CC5) PC = addr; break;
  3779.         case  6: if (CC6) PC = addr; break;
  3780.         case  7: if (CC7) PC = addr; break;
  3781.         case  8: if (CC8) PC = addr; break;
  3782.         case  9: if (CC9) PC = addr; break;
  3783.         case 10: if (CCA) PC = addr; break;
  3784.         case 11: if (CCB) PC = addr; break;
  3785.         case 12: if (CCC) PC = addr; break;
  3786.         case 13: if (CCD) PC = addr; break;
  3787.         case 14: if (CCE) PC = addr; break;
  3788.         case 15: if (CCF) PC = addr; break;
  3789.     }
  3790.     change_pc16bew(PC);
  3791. }
  3792.  
  3793. /******************************************
  3794.  jp      cc,addr(rd)
  3795.  flags:  ------
  3796.  ******************************************/
  3797. static void Z5E_ddN0_cccc_addr(void)
  3798. {
  3799.     GET_CCC(OP0,NIB3);
  3800.     GET_DST(OP0,NIB2);
  3801.     GET_ADDR(OP1);
  3802.     addr += RW(dst);
  3803.     switch (cc) {
  3804.         case  0: if (CC0) PC = addr; break;
  3805.         case  1: if (CC1) PC = addr; break;
  3806.         case  2: if (CC2) PC = addr; break;
  3807.         case  3: if (CC3) PC = addr; break;
  3808.         case  4: if (CC4) PC = addr; break;
  3809.         case  5: if (CC5) PC = addr; break;
  3810.         case  6: if (CC6) PC = addr; break;
  3811.         case  7: if (CC7) PC = addr; break;
  3812.         case  8: if (CC8) PC = addr; break;
  3813.         case  9: if (CC9) PC = addr; break;
  3814.         case 10: if (CCA) PC = addr; break;
  3815.         case 11: if (CCB) PC = addr; break;
  3816.         case 12: if (CCC) PC = addr; break;
  3817.         case 13: if (CCD) PC = addr; break;
  3818.         case 14: if (CCE) PC = addr; break;
  3819.         case 15: if (CCF) PC = addr; break;
  3820.     }
  3821.     change_pc16bew(PC);
  3822. }
  3823.  
  3824. /******************************************
  3825.  call     addr
  3826.  flags:  ------
  3827.  ******************************************/
  3828. static void Z5F_0000_0000_addr(void)
  3829. {
  3830.     GET_ADDR(OP1);
  3831.     PUSHW( SP, PC );
  3832.     PC = addr;
  3833.     change_pc16bew(PC);
  3834. }
  3835.  
  3836. /******************************************
  3837.  call     addr(rd)
  3838.  flags:  ------
  3839.  ******************************************/
  3840. static void Z5F_ddN0_0000_addr(void)
  3841. {
  3842.     GET_DST(OP0,NIB2);
  3843.     GET_ADDR(OP1);
  3844.     PUSHW( SP, PC );
  3845.     addr += RW(dst);
  3846.     PC = addr;
  3847.     change_pc16bew(PC);
  3848. }
  3849.  
  3850. /******************************************
  3851.  ldb     rbd,addr
  3852.  flags:  ------
  3853.  ******************************************/
  3854. static void Z60_0000_dddd_addr(void)
  3855. {
  3856.     GET_DST(OP0,NIB3);
  3857.     GET_ADDR(OP1);
  3858.     RB(dst) = RDMEM_B(addr);
  3859. }
  3860.  
  3861. /******************************************
  3862.  ldb     rbd,addr(rs)
  3863.  flags:  ------
  3864.  ******************************************/
  3865. static void Z60_ssN0_dddd_addr(void)
  3866. {
  3867.     GET_DST(OP0,NIB3);
  3868.     GET_SRC(OP0,NIB2);
  3869.     GET_ADDR(OP1);
  3870.     addr += RW(src);
  3871.     RB(dst) = RDMEM_B(addr);
  3872. }
  3873.  
  3874. /******************************************
  3875.  ld      rd,addr
  3876.  flags:  ------
  3877.  ******************************************/
  3878. static void Z61_0000_dddd_addr(void)
  3879. {
  3880.     GET_DST(OP0,NIB3);
  3881.     GET_ADDR(OP1);
  3882.     RW(dst) = RDMEM_W(addr);
  3883. }
  3884.  
  3885. /******************************************
  3886.  ld      rd,addr(rs)
  3887.  flags:  ------
  3888.  ******************************************/
  3889. static void Z61_ssN0_dddd_addr(void)
  3890. {
  3891.     GET_DST(OP0,NIB3);
  3892.     GET_SRC(OP0,NIB2);
  3893.     GET_ADDR(OP1);
  3894.     addr += RW(src);
  3895.     RW(dst) = RDMEM_W(addr);
  3896. }
  3897.  
  3898. /******************************************
  3899.  resb     addr,imm4
  3900.  flags:  ------
  3901.  ******************************************/
  3902. static void Z62_0000_imm4_addr(void)
  3903. {
  3904.     GET_BIT(OP0);
  3905.     GET_ADDR(OP1);
  3906.     WRMEM_B( addr, RDMEM_B(addr) & ~bit );
  3907. }
  3908.  
  3909. /******************************************
  3910.  resb     addr(rd),imm4
  3911.  flags:  ------
  3912.  ******************************************/
  3913. static void Z62_ddN0_imm4_addr(void)
  3914. {
  3915.     GET_BIT(OP0);
  3916.     GET_DST(OP0,NIB2);
  3917.     GET_ADDR(OP1);
  3918.     addr += RW(dst);
  3919.     WRMEM_B( addr, RDMEM_B(addr) & ~bit );
  3920. }
  3921.  
  3922. /******************************************
  3923.  res     addr,imm4
  3924.  flags:  ------
  3925.  ******************************************/
  3926. static void Z63_0000_imm4_addr(void)
  3927. {
  3928.     GET_BIT(OP0);
  3929.     GET_ADDR(OP1);
  3930.     WRMEM_W( addr, RDMEM_W(addr) & ~bit );
  3931. }
  3932.  
  3933. /******************************************
  3934.  res     addr(rd),imm4
  3935.  flags:  ------
  3936.  ******************************************/
  3937. static void Z63_ddN0_imm4_addr(void)
  3938. {
  3939.     GET_BIT(OP0);
  3940.     GET_DST(OP0,NIB2);
  3941.     GET_ADDR(OP1);
  3942.     addr += RW(dst);
  3943.     WRMEM_W( addr, RDMEM_W(addr) & ~bit );
  3944. }
  3945.  
  3946. /******************************************
  3947.  setb     addr,imm4
  3948.  flags:  ------
  3949.  ******************************************/
  3950. static void Z64_0000_imm4_addr(void)
  3951. {
  3952.     GET_BIT(OP0);
  3953.     GET_ADDR(OP1);
  3954.     WRMEM_B( addr, RDMEM_B(addr) | bit );
  3955. }
  3956.  
  3957. /******************************************
  3958.  setb     addr(rd),imm4
  3959.  flags:  ------
  3960.  ******************************************/
  3961. static void Z64_ddN0_imm4_addr(void)
  3962. {
  3963.     GET_BIT(OP0);
  3964.     GET_DST(OP0,NIB2);
  3965.     GET_ADDR(OP1);
  3966.     addr += RW(dst);
  3967.     WRMEM_B( addr, RDMEM_B(addr) | bit );
  3968. }
  3969.  
  3970. /******************************************
  3971.  set     addr,imm4
  3972.  flags:  ------
  3973.  ******************************************/
  3974. static void Z65_0000_imm4_addr(void)
  3975. {
  3976.     GET_BIT(OP0);
  3977.     GET_ADDR(OP1);
  3978.     WRMEM_W( addr, RDMEM_W(addr) | bit );
  3979. }
  3980.  
  3981. /******************************************
  3982.  set     addr(rd),imm4
  3983.  flags:  ------
  3984.  ******************************************/
  3985. static void Z65_ddN0_imm4_addr(void)
  3986. {
  3987.     GET_BIT(OP0);
  3988.     GET_DST(OP0,NIB2);
  3989.     GET_ADDR(OP1);
  3990.     addr += RW(dst);
  3991.     WRMEM_W( addr, RDMEM_W(addr) | bit );
  3992. }
  3993.  
  3994. /******************************************
  3995.  bitb     addr,imm4
  3996.  flags:  -Z----
  3997.  ******************************************/
  3998. static void Z66_0000_imm4_addr(void)
  3999. {
  4000.     GET_BIT(OP0);
  4001.     GET_ADDR(OP1);
  4002.     if ( RDMEM_B(addr) & bit) CLR_Z; else SET_Z;
  4003. }
  4004.  
  4005. /******************************************
  4006.  bitb     addr(rd),imm4
  4007.  flags:  -Z----
  4008.  ******************************************/
  4009. static void Z66_ddN0_imm4_addr(void)
  4010. {
  4011.     GET_BIT(OP0);
  4012.     GET_DST(OP0,NIB2);
  4013.     GET_ADDR(OP1);
  4014.     addr += RW(dst);
  4015.     if ( RDMEM_B(addr) & bit) CLR_Z; else SET_Z;
  4016. }
  4017.  
  4018. /******************************************
  4019.  bit     addr,imm4
  4020.  flags:  -Z----
  4021.  ******************************************/
  4022. static void Z67_0000_imm4_addr(void)
  4023. {
  4024.     GET_BIT(OP0);
  4025.     GET_ADDR(OP1);
  4026.     if ( RDMEM_W(addr) & bit) CLR_Z; else SET_Z;
  4027. }
  4028.  
  4029. /******************************************
  4030.  bit     addr(rd),imm4
  4031.  flags:  -Z----
  4032.  ******************************************/
  4033. static void Z67_ddN0_imm4_addr(void)
  4034. {
  4035.     GET_BIT(OP0);
  4036.     GET_DST(OP0,NIB2);
  4037.     GET_ADDR(OP1);
  4038.     addr += RW(dst);
  4039.     if ( RDMEM_W(addr) & bit) CLR_Z; else SET_Z;
  4040. }
  4041.  
  4042. /******************************************
  4043.  incb     addr,imm4m1
  4044.  flags:  -ZSV--
  4045.  ******************************************/
  4046. static void Z68_0000_imm4m1_addr(void)
  4047. {
  4048.     GET_I4M1(OP0,NIB3);
  4049.     GET_ADDR(OP1);
  4050.     WRMEM_B( addr, INCB(RDMEM_B(addr), i4p1) );
  4051. }
  4052.  
  4053. /******************************************
  4054.  incb     addr(rd),imm4m1
  4055.  flags:  -ZSV--
  4056.  ******************************************/
  4057. static void Z68_ddN0_imm4m1_addr(void)
  4058. {
  4059.     GET_I4M1(OP0,NIB3);
  4060.     GET_DST(OP0,NIB2);
  4061.     GET_ADDR(OP1);
  4062.     addr += RW(dst);
  4063.     WRMEM_B( addr, INCB(RDMEM_B(addr), i4p1) );
  4064. }
  4065.  
  4066. /******************************************
  4067.  inc     addr,imm4m1
  4068.  flags:  -ZSV--
  4069.  ******************************************/
  4070. static void Z69_0000_imm4m1_addr(void)
  4071. {
  4072.     GET_I4M1(OP0,NIB3);
  4073.     GET_ADDR(OP1);
  4074.     WRMEM_W( addr, INCW(RDMEM_W(addr), i4p1) );
  4075. }
  4076.  
  4077. /******************************************
  4078.  inc     addr(rd),imm4m1
  4079.  flags:  -ZSV--
  4080.  ******************************************/
  4081. static void Z69_ddN0_imm4m1_addr(void)
  4082. {
  4083.     GET_I4M1(OP0,NIB3);
  4084.     GET_DST(OP0,NIB2);
  4085.     GET_ADDR(OP1);
  4086.     addr += RW(dst);
  4087.     WRMEM_W( addr, INCW(RDMEM_W(addr), i4p1) );
  4088. }
  4089.  
  4090. /******************************************
  4091.  decb     addr,imm4m1
  4092.  flags:  -ZSV--
  4093.  ******************************************/
  4094. static void Z6A_0000_imm4m1_addr(void)
  4095. {
  4096.     GET_I4M1(OP0,NIB3);
  4097.     GET_ADDR(OP1);
  4098.     WRMEM_B( addr, DECB(RDMEM_B(addr), i4p1) );
  4099. }
  4100.  
  4101. /******************************************
  4102.  decb     addr(rd),imm4m1
  4103.  flags:  -ZSV--
  4104.  ******************************************/
  4105. static void Z6A_ddN0_imm4m1_addr(void)
  4106. {
  4107.     GET_I4M1(OP0,NIB3);
  4108.     GET_DST(OP0,NIB2);
  4109.     GET_ADDR(OP1);
  4110.     addr += RW(dst);
  4111.     WRMEM_B( addr, DECB(RDMEM_B(addr), i4p1) );
  4112. }
  4113.  
  4114. /******************************************
  4115.  dec     addr,imm4m1
  4116.  flags:  -ZSV--
  4117.  ******************************************/
  4118. static void Z6B_0000_imm4m1_addr(void)
  4119. {
  4120.     GET_I4M1(OP0,NIB3);
  4121.     GET_ADDR(OP1);
  4122.     WRMEM_W( addr, DECW(RDMEM_W(addr), i4p1) );
  4123. }
  4124.  
  4125. /******************************************
  4126.  dec     addr(rd),imm4m1
  4127.  flags:  -ZSV--
  4128.  ******************************************/
  4129. static void Z6B_ddN0_imm4m1_addr(void)
  4130. {
  4131.     GET_I4M1(OP0,NIB3);
  4132.     GET_DST(OP0,NIB2);
  4133.     GET_ADDR(OP1);
  4134.     addr += RW(dst);
  4135.     WRMEM_W( addr, DECW(RDMEM_W(addr), i4p1) );
  4136. }
  4137.  
  4138. /******************************************
  4139.  exb     rbd,addr
  4140.  flags:  ------
  4141.  ******************************************/
  4142. static void Z6C_0000_dddd_addr(void)
  4143. {
  4144.     GET_DST(OP0,NIB3);
  4145.     GET_ADDR(OP1);
  4146.     UINT8 tmp = RDMEM_B(addr);
  4147.     WRMEM_B(addr, RB(dst));
  4148.     RB(dst) = tmp;
  4149. }
  4150.  
  4151. /******************************************
  4152.  exb     rbd,addr(rs)
  4153.  flags:  ------
  4154.  ******************************************/
  4155. static void Z6C_ssN0_dddd_addr(void)
  4156. {
  4157.     GET_DST(OP0,NIB3);
  4158.     GET_SRC(OP0,NIB2);
  4159.     GET_ADDR(OP1);
  4160.     UINT8 tmp;
  4161.     addr += RW(src);
  4162.     tmp = RDMEM_B(addr);
  4163.     WRMEM_B(addr, RB(dst));
  4164.     RB(dst) = tmp;
  4165. }
  4166.  
  4167. /******************************************
  4168.  ex      rd,addr
  4169.  flags:  ------
  4170.  ******************************************/
  4171. static void Z6D_0000_dddd_addr(void)
  4172. {
  4173.     GET_DST(OP0,NIB3);
  4174.     GET_ADDR(OP1);
  4175.     UINT16 tmp = RDMEM_W(addr);
  4176.     WRMEM_W( addr, RW(dst) );
  4177.     RW(dst) = tmp;
  4178. }
  4179.  
  4180. /******************************************
  4181.  ex      rd,addr(rs)
  4182.  flags:  ------
  4183.  ******************************************/
  4184. static void Z6D_ssN0_dddd_addr(void)
  4185. {
  4186.     GET_DST(OP0,NIB3);
  4187.     GET_SRC(OP0,NIB2);
  4188.     GET_ADDR(OP1);
  4189.     UINT16 tmp;
  4190.     addr += RW(src);
  4191.     tmp = RDMEM_W(addr);
  4192.     WRMEM_W( addr, RW(dst) );
  4193.     RW(dst) = tmp;
  4194. }
  4195.  
  4196. /******************************************
  4197.  ldb     addr,rbs
  4198.  flags:  ------
  4199.  ******************************************/
  4200. static void Z6E_0000_ssss_addr(void)
  4201. {
  4202.     GET_SRC(OP0,NIB3);
  4203.     GET_ADDR(OP1);
  4204.     WRMEM_B( addr, RB(src) );
  4205. }
  4206.  
  4207. /******************************************
  4208.  ldb     addr(rd),rbs
  4209.  flags:  ------
  4210.  ******************************************/
  4211. static void Z6E_ddN0_ssss_addr(void)
  4212. {
  4213.     GET_SRC(OP0,NIB3);
  4214.     GET_DST(OP0,NIB2);
  4215.     GET_ADDR(OP1);
  4216.     addr += RW(dst);
  4217.     WRMEM_B( addr, RB(src) );
  4218. }
  4219.  
  4220. /******************************************
  4221.  ld      addr,rs
  4222.  flags:  ------
  4223.  ******************************************/
  4224. static void Z6F_0000_ssss_addr(void)
  4225. {
  4226.     GET_SRC(OP0,NIB3);
  4227.     GET_ADDR(OP1);
  4228.     WRMEM_W( addr, RW(src) );
  4229. }
  4230.  
  4231. /******************************************
  4232.  ld      addr(rd),rs
  4233.  flags:  ------
  4234.  ******************************************/
  4235. static void Z6F_ddN0_ssss_addr(void)
  4236. {
  4237.     GET_SRC(OP0,NIB3);
  4238.     GET_DST(OP0,NIB2);
  4239.     GET_ADDR(OP1);
  4240.     addr += RW(dst);
  4241.     WRMEM_W( addr, RW(src) );
  4242. }
  4243.  
  4244. /******************************************
  4245.  ldb     rbd,rs(rx)
  4246.  flags:  ------
  4247.  ******************************************/
  4248. static void Z70_ssN0_dddd_0000_xxxx_0000_0000(void)
  4249. {
  4250.     GET_DST(OP0,NIB3);
  4251.     GET_SRC(OP0,NIB2);
  4252.     GET_IDX(OP1,NIB1);
  4253.     RB(dst) = RDMEM_B( (UINT16)(RW(src) + RW(idx)) );
  4254. }
  4255.  
  4256. /******************************************
  4257.  ld      rd,rs(rx)
  4258.  flags:  ------
  4259.  ******************************************/
  4260. static void Z71_ssN0_dddd_0000_xxxx_0000_0000(void)
  4261. {
  4262.     GET_DST(OP0,NIB3);
  4263.     GET_SRC(OP0,NIB2);
  4264.     GET_IDX(OP1,NIB1);
  4265.     RW(dst) = RDMEM_W( (UINT16)(RW(src) + RW(idx)) );
  4266. }
  4267.  
  4268. /******************************************
  4269.  ldb     rd(rx),rbs
  4270.  flags:  ------
  4271.  ******************************************/
  4272. static void Z72_ddN0_ssss_0000_xxxx_0000_0000(void)
  4273. {
  4274.     GET_SRC(OP0,NIB3);
  4275.     GET_DST(OP0,NIB2);
  4276.     GET_IDX(OP1,NIB1);
  4277.     WRMEM_B( (UINT16)(RW(dst) + RW(idx)), RB(src) );
  4278. }
  4279.  
  4280. /******************************************
  4281.  ld      rd(rx),rs
  4282.  flags:  ------
  4283.  ******************************************/
  4284. static void Z73_ddN0_ssss_0000_xxxx_0000_0000(void)
  4285. {
  4286.     GET_SRC(OP0,NIB3);
  4287.     GET_DST(OP0,NIB2);
  4288.     GET_IDX(OP1,NIB1);
  4289.     WRMEM_W( (UINT16)(RW(dst) + RW(idx)), RW(src) );
  4290. }
  4291.  
  4292. /******************************************
  4293.  lda     prd,rs(rx)
  4294.  flags:  ------
  4295.  ******************************************/
  4296. static void Z74_ssN0_dddd_0000_xxxx_0000_0000(void)
  4297. {
  4298.     GET_DST(OP0,NIB3);
  4299.     GET_SRC(OP0,NIB2);
  4300.     GET_IDX(OP1,NIB1);
  4301.     RW(dst) = (UINT16)(RW(src) + RW(idx));
  4302. }
  4303.  
  4304. /******************************************
  4305.  ldl     rrd,rs(rx)
  4306.  flags:  ------
  4307.  ******************************************/
  4308. static void Z75_ssN0_dddd_0000_xxxx_0000_0000(void)
  4309. {
  4310.     GET_DST(OP0,NIB3);
  4311.     GET_SRC(OP0,NIB2);
  4312.     GET_IDX(OP1,NIB1);
  4313.     RL(dst) = RDMEM_L( (UINT16)(RW(src) + RW(idx)) );
  4314. }
  4315.  
  4316. /******************************************
  4317.  lda     prd,addr
  4318.  flags:  ------
  4319.  ******************************************/
  4320. static void Z76_0000_dddd_addr(void)
  4321. {
  4322.     GET_DST(OP0,NIB3);
  4323.     GET_ADDR(OP1);
  4324.     RW(dst) = addr;
  4325. }
  4326.  
  4327. /******************************************
  4328.  lda     prd,addr(rs)
  4329.  flags:  ------
  4330.  ******************************************/
  4331. static void Z76_ssN0_dddd_addr(void)
  4332. {
  4333.     GET_DST(OP0,NIB3);
  4334.     GET_SRC(OP0,NIB2);
  4335.     GET_ADDR(OP1);
  4336.     addr += RW(src);
  4337.     RW(dst) = addr;
  4338. }
  4339.  
  4340. /******************************************
  4341.  ldl     rd(rx),rrs
  4342.  flags:  ------
  4343.  ******************************************/
  4344. static void Z77_ddN0_ssss_0000_xxxx_0000_0000(void)
  4345. {
  4346.     GET_SRC(OP0,NIB3);
  4347.     GET_DST(OP0,NIB2);
  4348.     GET_IDX(OP1,NIB1);
  4349.     WRMEM_L( (UINT16)(RW(dst) + RW(idx)), RL(src) );
  4350. }
  4351.  
  4352. /******************************************
  4353.  rsvd78
  4354.  flags:  ------
  4355.  ******************************************/
  4356. static void Z78_imm8(void)
  4357. {
  4358.     GET_IMM8(0);
  4359.     LOG(("Z8K#%d %04x: rsvd78 $%02x\n", cpu_getactivecpu(), PC, imm8));
  4360.     if (FCW & F_EPU) {
  4361.         /* Z8001 EPU code goes here */
  4362.         (void)imm8;
  4363.     }
  4364. }
  4365.  
  4366. /******************************************
  4367.  ldps     addr
  4368.  flags:  CZSVDH
  4369.  ******************************************/
  4370. static void Z79_0000_0000_addr(void)
  4371. {
  4372.     GET_ADDR(OP1);
  4373.     UINT16 fcw;
  4374.     fcw = RDMEM_W(addr);
  4375.     PC    = RDMEM_W((UINT16)(addr + 2));
  4376.     CHANGE_FCW(fcw); /* check for user/system mode change */
  4377.     change_pc16bew(PC);
  4378. }
  4379.  
  4380. /******************************************
  4381.  ldps     addr(rs)
  4382.  flags:  CZSVDH
  4383.  ******************************************/
  4384. static void Z79_ssN0_0000_addr(void)
  4385. {
  4386.     GET_SRC(OP0,NIB2);
  4387.     GET_ADDR(OP1);
  4388.     UINT16 fcw;
  4389.     addr += RW(src);
  4390.     fcw = RDMEM_W(addr);
  4391.     PC    = RDMEM_W((UINT16)(addr + 2));
  4392.     CHANGE_FCW(fcw); /* check for user/system mode change */
  4393.     change_pc16bew(PC);
  4394. }
  4395.  
  4396. /******************************************
  4397.  halt
  4398.  flags:  ------
  4399.  ******************************************/
  4400. static void Z7A_0000_0000(void)
  4401. {
  4402.     IRQ_REQ |= Z8000_HALT;
  4403.     if (z8000_ICount > 0) z8000_ICount = 0;
  4404. }
  4405.  
  4406. /******************************************
  4407.  iret
  4408.  flags:  CZSVDH
  4409.  ******************************************/
  4410. static void Z7B_0000_0000(void)
  4411. {
  4412.     UINT16 tag, fcw;
  4413.     tag = POPW( SP );    /* get type tag */
  4414.     fcw = POPW( SP );    /* get FCW    */
  4415.     PC    = POPW( SP );    /* get PC    */
  4416.     IRQ_SRV &= ~tag;    /* remove IRQ serviced flag */
  4417.     CHANGE_FCW(fcw);         /* check for user/system mode change */
  4418.     change_pc16bew(PC);
  4419.     LOG(("Z8K#%d IRET tag $%04x, fcw $%04x, pc $%04x\n", cpu_getactivecpu(), tag, fcw, PC));
  4420. }
  4421.  
  4422. /******************************************
  4423.  mset
  4424.  flags:  ------
  4425.  ******************************************/
  4426. static void Z7B_0000_1000(void)
  4427. {
  4428.     /* set mu-0 line */
  4429. }
  4430.  
  4431. /******************************************
  4432.  mres
  4433.  flags:  ------
  4434.  ******************************************/
  4435. static void Z7B_0000_1001(void)
  4436. {
  4437.     /* reset mu-0 line */
  4438. }
  4439.  
  4440. /******************************************
  4441.  mbit
  4442.  flags:  CZS---
  4443.  ******************************************/
  4444. static void Z7B_0000_1010(void)
  4445. {
  4446.     /* test mu-I line */
  4447. }
  4448.  
  4449. /******************************************
  4450.  mreq     rd
  4451.  flags:  -ZS---
  4452.  ******************************************/
  4453. static void Z7B_dddd_1101(void)
  4454. {
  4455.     /* test mu-I line, invert cascade to mu-0  */
  4456. }
  4457.  
  4458. /******************************************
  4459.  di      i2
  4460.  flags:  ------
  4461.  ******************************************/
  4462. static void Z7C_0000_00ii(void)
  4463. {
  4464.     GET_IMM2(OP0,NIB3);
  4465.     UINT16 fcw = FCW;
  4466.     fcw &= ~(imm2 << 11);
  4467.     CHANGE_FCW(fcw);
  4468. }
  4469.  
  4470. /******************************************
  4471.  ei      i2
  4472.  flags:  ------
  4473.  ******************************************/
  4474. static void Z7C_0000_01ii(void)
  4475. {
  4476.     GET_IMM2(OP0,NIB3);
  4477.     UINT16 fcw = FCW;
  4478.     fcw |= imm2 << 11;
  4479.     CHANGE_FCW(fcw);
  4480. }
  4481.  
  4482. /******************************************
  4483.  ldctl     rd,ctrl
  4484.  flags:  ------
  4485.  ******************************************/
  4486. static void Z7D_dddd_0ccc(void)
  4487. {
  4488.     GET_IMM3(OP0,NIB3);
  4489.     GET_DST(OP0,NIB2);
  4490.     switch (imm3) {
  4491.         case 0:
  4492.             RW(dst) = FCW;
  4493.             break;
  4494.         case 3:
  4495.             RW(dst) = REFRESH;
  4496.             break;
  4497.         case 5:
  4498.             RW(dst) = PSAP;
  4499.             break;
  4500.         case 7:
  4501.             RW(dst) = NSP;
  4502.             break;
  4503.         default:
  4504.             LOG(("Z8K#%d LDCTL R%d,%d\n", cpu_getactivecpu(), dst, imm3));
  4505.     }
  4506. }
  4507.  
  4508. /******************************************
  4509.  ldctl     ctrl,rs
  4510.  flags:  ------
  4511.  ******************************************/
  4512. static void Z7D_ssss_1ccc(void)
  4513. {
  4514.     GET_IMM3(OP0,NIB3);
  4515.     GET_SRC(OP0,NIB2);
  4516.     switch (imm3) {
  4517.         case 0:
  4518.             {
  4519.                 UINT16 fcw;
  4520.                 fcw = RW(src);
  4521.                 CHANGE_FCW(fcw); /* check for user/system mode change */
  4522.             }
  4523.             break;
  4524.         case 3:
  4525.             REFRESH = RW(src);
  4526.             break;
  4527.         case 5:
  4528.             PSAP = RW(src);
  4529.             break;
  4530.         case 7:
  4531.             NSP = RW(src);
  4532.             break;
  4533.         default:
  4534.             LOG(("Z8K#%d LDCTL %d,R%d\n", cpu_getactivecpu(), imm3, src));
  4535.     }
  4536. }
  4537.  
  4538. /******************************************
  4539.  rsvd7e
  4540.  flags:  ------
  4541.  ******************************************/
  4542. static void Z7E_imm8(void)
  4543. {
  4544.     GET_IMM8(0);
  4545.     LOG(("Z8K#%d %04x: rsvd7e $%02x\n", cpu_getactivecpu(), PC, imm8));
  4546.     if (FCW & F_EPU) {
  4547.         /* Z8001 EPU code goes here */
  4548.         (void)imm8;
  4549.     }
  4550. }
  4551.  
  4552. /******************************************
  4553.  sc      imm8
  4554.  flags:  CZSVDH
  4555.  ******************************************/
  4556. static void Z7F_imm8(void)
  4557. {
  4558.     GET_IMM8(0);
  4559.     /* execute system call via IRQ */
  4560.     IRQ_REQ = Z8000_SYSCALL | imm8;
  4561.  
  4562. }
  4563.  
  4564. /******************************************
  4565.  addb     rbd,rbs
  4566.  flags:  CZSVDH
  4567.  ******************************************/
  4568. static void Z80_ssss_dddd(void)
  4569. {
  4570.     GET_DST(OP0,NIB3);
  4571.     GET_SRC(OP0,NIB2);
  4572.     RB(dst) = ADDB( RB(dst), RB(src) );
  4573. }
  4574.  
  4575. /******************************************
  4576.  add     rd,rs
  4577.  flags:  CZSV--
  4578.  ******************************************/
  4579. static void Z81_ssss_dddd(void)
  4580. {
  4581.     GET_DST(OP0,NIB3);
  4582.     GET_SRC(OP0,NIB2);
  4583.     RW(dst) = ADDW( RW(dst), RW(src) );
  4584. }
  4585.  
  4586. /******************************************
  4587.  subb     rbd,rbs
  4588.  flags:  CZSVDH
  4589.  ******************************************/
  4590. static void Z82_ssss_dddd(void)
  4591. {
  4592.     GET_DST(OP0,NIB3);
  4593.     GET_SRC(OP0,NIB2);
  4594.     RB(dst) = SUBB( RB(dst), RB(src) );
  4595. }
  4596.  
  4597. /******************************************
  4598.  sub     rd,rs
  4599.  flags:  CZSV--
  4600.  ******************************************/
  4601. static void Z83_ssss_dddd(void)
  4602. {
  4603.     GET_DST(OP0,NIB3);
  4604.     GET_SRC(OP0,NIB2);
  4605.     RW(dst) = SUBW( RW(dst), RW(src) );
  4606. }
  4607.  
  4608. /******************************************
  4609.  orb     rbd,rbs
  4610.  flags:  CZSP--
  4611.  ******************************************/
  4612. static void Z84_ssss_dddd(void)
  4613. {
  4614.     GET_DST(OP0,NIB3);
  4615.     GET_SRC(OP0,NIB2);
  4616.     RB(dst) = ORB( RB(dst), RB(src) );
  4617. }
  4618.  
  4619. /******************************************
  4620.  or      rd,rs
  4621.  flags:  CZS---
  4622.  ******************************************/
  4623. static void Z85_ssss_dddd(void)
  4624. {
  4625.     GET_DST(OP0,NIB3);
  4626.     GET_SRC(OP0,NIB2);
  4627.     RW(dst) = ORW( RW(dst), RW(src) );
  4628. }
  4629.  
  4630. /******************************************
  4631.  andb     rbd,rbs
  4632.  flags:  -ZSP--
  4633.  ******************************************/
  4634. static void Z86_ssss_dddd(void)
  4635. {
  4636.     GET_DST(OP0,NIB3);
  4637.     GET_SRC(OP0,NIB2);
  4638.     RB(dst) = ANDB( RB(dst), RB(src) );
  4639. }
  4640.  
  4641. /******************************************
  4642.  and     rd,rs
  4643.  flags:  -ZS---
  4644.  ******************************************/
  4645. static void Z87_ssss_dddd(void)
  4646. {
  4647.     GET_DST(OP0,NIB3);
  4648.     GET_SRC(OP0,NIB2);
  4649.     RW(dst) = ANDW( RW(dst), RW(src) );
  4650. }
  4651.  
  4652. /******************************************
  4653.  xorb     rbd,rbs
  4654.  flags:  -ZSP--
  4655.  ******************************************/
  4656. static void Z88_ssss_dddd(void)
  4657. {
  4658.     GET_DST(OP0,NIB3);
  4659.     GET_SRC(OP0,NIB2);
  4660.     RB(dst) = XORB( RB(dst), RB(src) );
  4661. }
  4662.  
  4663. /******************************************
  4664.  xor     rd,rs
  4665.  flags:  -ZS---
  4666.  ******************************************/
  4667. static void Z89_ssss_dddd(void)
  4668. {
  4669.     GET_DST(OP0,NIB3);
  4670.     GET_SRC(OP0,NIB2);
  4671.     RW(dst) = XORW( RW(dst), RW(src) );
  4672. }
  4673.  
  4674. /******************************************
  4675.  cpb     rbd,rbs
  4676.  flags:  CZSV--
  4677.  ******************************************/
  4678. static void Z8A_ssss_dddd(void)
  4679. {
  4680.     GET_DST(OP0,NIB3);
  4681.     GET_SRC(OP0,NIB2);
  4682.     CPB( RB(dst), RB(src) );
  4683. }
  4684.  
  4685. /******************************************
  4686.  cp      rd,rs
  4687.  flags:  CZSV--
  4688.  ******************************************/
  4689. static void Z8B_ssss_dddd(void)
  4690. {
  4691.     GET_DST(OP0,NIB3);
  4692.     GET_SRC(OP0,NIB2);
  4693.     CPW( RW(dst), RW(src) );
  4694. }
  4695.  
  4696. /******************************************
  4697.  comb     rbd
  4698.  flags:  -ZSP--
  4699.  ******************************************/
  4700. static void Z8C_dddd_0000(void)
  4701. {
  4702.     GET_DST(OP0,NIB2);
  4703.     RB(dst) = COMB( RB(dst) );
  4704. }
  4705.  
  4706. /******************************************
  4707.  negb     rbd
  4708.  flags:  CZSV--
  4709.  ******************************************/
  4710. static void Z8C_dddd_0010(void)
  4711. {
  4712.     GET_DST(OP0,NIB2);
  4713.     RB(dst) = NEGB( RB(dst) );
  4714. }
  4715.  
  4716. /******************************************
  4717.  testb     rbd
  4718.  flags:  -ZSP--
  4719.  ******************************************/
  4720. static void Z8C_dddd_0100(void)
  4721. {
  4722.     GET_DST(OP0,NIB2);
  4723.     TESTB( RB(dst) );
  4724. }
  4725.  
  4726. /******************************************
  4727.  tsetb     rbd
  4728.  flags:  --S---
  4729.  ******************************************/
  4730. static void Z8C_dddd_0110(void)
  4731. {
  4732.     GET_DST(OP0,NIB2);
  4733.     if (RB(dst) & S08) SET_S; else CLR_S;
  4734.     RB(dst) = 0xff;
  4735. }
  4736.  
  4737. /******************************************
  4738.  clrb     rbd
  4739.  flags:  ------
  4740.  ******************************************/
  4741. static void Z8C_dddd_1000(void)
  4742. {
  4743.     GET_DST(OP0,NIB2);
  4744.     RB(dst) = 0;
  4745. }
  4746.  
  4747. /******************************************
  4748.  nop
  4749.  flags:  ------
  4750.  ******************************************/
  4751. static void Z8D_0000_0111(void)
  4752. {
  4753.     /* nothing */
  4754. }
  4755.  
  4756. /******************************************
  4757.  com     rd
  4758.  flags:  -ZS---
  4759.  ******************************************/
  4760. static void Z8D_dddd_0000(void)
  4761. {
  4762.     GET_DST(OP0,NIB2);
  4763.     RW(dst) = COMW( RW(dst) );
  4764. }
  4765.  
  4766. /******************************************
  4767.  neg     rd
  4768.  flags:  CZSV--
  4769.  ******************************************/
  4770. static void Z8D_dddd_0010(void)
  4771. {
  4772.     GET_DST(OP0,NIB2);
  4773.     RW(dst) = NEGW( RW(dst) );
  4774. }
  4775.  
  4776. /******************************************
  4777.  test     rd
  4778.  flags:  ------
  4779.  ******************************************/
  4780. static void Z8D_dddd_0100(void)
  4781. {
  4782.     GET_DST(OP0,NIB2);
  4783.     TESTW( RW(dst) );
  4784. }
  4785.  
  4786. /******************************************
  4787.  tset     rd
  4788.  flags:  --S---
  4789.  ******************************************/
  4790. static void Z8D_dddd_0110(void)
  4791. {
  4792.     GET_DST(OP0,NIB2);
  4793.     if (RW(dst) & S16) SET_S; else CLR_S;
  4794.     RW(dst) = 0xffff;
  4795. }
  4796.  
  4797. /******************************************
  4798.  clr     rd
  4799.  flags:  ------
  4800.  ******************************************/
  4801. static void Z8D_dddd_1000(void)
  4802. {
  4803.     GET_DST(OP0,NIB2);
  4804.     RW(dst) = 0;
  4805. }
  4806.  
  4807. /******************************************
  4808.  setflg  imm4
  4809.  flags:  CZSV--
  4810.  ******************************************/
  4811. static void Z8D_imm4_0001(void)
  4812. {
  4813.     FCW |= Z.op[0] & 0x00f0;
  4814. }
  4815.  
  4816. /******************************************
  4817.  resflg  imm4
  4818.  flags:  CZSV--
  4819.  ******************************************/
  4820. static void Z8D_imm4_0011(void)
  4821. {
  4822.     FCW &= ~(Z.op[0] & 0x00f0);
  4823. }
  4824.  
  4825. /******************************************
  4826.  comflg  flags
  4827.  flags:  CZSP--
  4828.  ******************************************/
  4829. static void Z8D_imm4_0101(void)
  4830. {
  4831.     FCW ^= (Z.op[0] & 0x00f0);
  4832. }
  4833.  
  4834. /******************************************
  4835.  ext8e     imm8
  4836.  flags:  ------
  4837.  ******************************************/
  4838. static void Z8E_imm8(void)
  4839. {
  4840.     GET_IMM8(0);
  4841.     LOG(("Z8K#%d %04x: ext8e  $%02x\n", cpu_getactivecpu(), PC, imm8));
  4842.     if (FCW & F_EPU) {
  4843.         /* Z8001 EPU code goes here */
  4844.         (void)imm8;
  4845.     }
  4846. }
  4847.  
  4848. /******************************************
  4849.  ext8f     imm8
  4850.  flags:  ------
  4851.  ******************************************/
  4852. static void Z8F_imm8(void)
  4853. {
  4854.     GET_IMM8(0);
  4855.     LOG(("Z8K#%d %04x: ext8f  $%02x\n", cpu_getactivecpu(), PC, imm8));
  4856.     if (FCW & F_EPU) {
  4857.         /* Z8001 EPU code goes here */
  4858.         (void)imm8;
  4859.     }
  4860. }
  4861.  
  4862. /******************************************
  4863.  cpl     rrd,rrs
  4864.  flags:  CZSV--
  4865.  ******************************************/
  4866. static void Z90_ssss_dddd(void)
  4867. {
  4868.     GET_DST(OP0,NIB3);
  4869.     GET_SRC(OP0,NIB2);
  4870.     CPL( RL(dst), RL(src) );
  4871. }
  4872.  
  4873. /******************************************
  4874.  pushl     @rd,rrs
  4875.  flags:  ------
  4876.  ******************************************/
  4877. static void Z91_ddN0_ssss(void)
  4878. {
  4879.     GET_SRC(OP0,NIB3);
  4880.     GET_DST(OP0,NIB2);
  4881.     PUSHL( dst, RL(src) );
  4882. }
  4883.  
  4884. /******************************************
  4885.  subl     rrd,rrs
  4886.  flags:  CZSV--
  4887.  ******************************************/
  4888. static void Z92_ssss_dddd(void)
  4889. {
  4890.     GET_DST(OP0,NIB3);
  4891.     GET_SRC(OP0,NIB2);
  4892.     RL(dst) = SUBL( RL(dst), RL(src) );
  4893. }
  4894.  
  4895. /******************************************
  4896.  push     @rd,rs
  4897.  flags:  ------
  4898.  ******************************************/
  4899. static void Z93_ddN0_ssss(void)
  4900. {
  4901.     GET_SRC(OP0,NIB3);
  4902.     GET_DST(OP0,NIB2);
  4903.     PUSHW(dst, RW(src));
  4904. }
  4905.  
  4906. /******************************************
  4907.  ldl     rrd,rrs
  4908.  flags:  ------
  4909.  ******************************************/
  4910. static void Z94_ssss_dddd(void)
  4911. {
  4912.     GET_DST(OP0,NIB3);
  4913.     GET_SRC(OP0,NIB2);
  4914.     RL(dst) = RL(src);
  4915. }
  4916.  
  4917. /******************************************
  4918.  popl     rrd,@rs
  4919.  flags:  ------
  4920.  ******************************************/
  4921. static void Z95_ssN0_dddd(void)
  4922. {
  4923.     GET_DST(OP0,NIB3);
  4924.     GET_SRC(OP0,NIB2);
  4925.     RL(dst) = POPL( src );
  4926. }
  4927.  
  4928. /******************************************
  4929.  addl     rrd,rrs
  4930.  flags:  CZSV--
  4931.  ******************************************/
  4932. static void Z96_ssss_dddd(void)
  4933. {
  4934.     GET_DST(OP0,NIB3);
  4935.     GET_SRC(OP0,NIB2);
  4936.     RL(dst) = ADDL( RL(dst), RL(src) );
  4937. }
  4938.  
  4939. /******************************************
  4940.  pop     rd,@rs
  4941.  flags:  ------
  4942.  ******************************************/
  4943. static void Z97_ssN0_dddd(void)
  4944. {
  4945.     GET_DST(OP0,NIB3);
  4946.     GET_SRC(OP0,NIB2);
  4947.     RW(dst) = POPW( src );
  4948. }
  4949.  
  4950. /******************************************
  4951.  multl     rqd,rrs
  4952.  flags:  CZSV--
  4953.  ******************************************/
  4954. static void Z98_ssss_dddd(void)
  4955. {
  4956.     GET_DST(OP0,NIB3);
  4957.     GET_SRC(OP0,NIB2);
  4958.     RQ(dst) = MULTL( RQ(dst), RL(src) );
  4959. }
  4960.  
  4961. /******************************************
  4962.  mult     rrd,rs
  4963.  flags:  CZSV--
  4964.  ******************************************/
  4965. static void Z99_ssss_dddd(void)
  4966. {
  4967.     GET_DST(OP0,NIB3);
  4968.     GET_SRC(OP0,NIB2);
  4969.     RL(dst) = MULTW( RL(dst), RW(src) );
  4970. }
  4971.  
  4972. /******************************************
  4973.  divl     rqd,rrs
  4974.  flags:  CZSV--
  4975.  ******************************************/
  4976. static void Z9A_ssss_dddd(void)
  4977. {
  4978.     GET_DST(OP0,NIB3);
  4979.     GET_SRC(OP0,NIB2);
  4980.     RQ(dst) = DIVL( RQ(dst), RL(src) );
  4981. }
  4982.  
  4983. /******************************************
  4984.  div     rrd,rs
  4985.  flags:  CZSV--
  4986.  ******************************************/
  4987. static void Z9B_ssss_dddd(void)
  4988. {
  4989.     GET_DST(OP0,NIB3);
  4990.     GET_SRC(OP0,NIB2);
  4991.     RL(dst) = DIVW( RL(dst), RW(src) );
  4992. }
  4993.  
  4994. /******************************************
  4995.  testl     rrd
  4996.  flags:  -ZS---
  4997.  ******************************************/
  4998. static void Z9C_dddd_1000(void)
  4999. {
  5000.     GET_DST(OP0,NIB2);
  5001.     CLR_ZS;
  5002.     if (!RL(dst)) SET_Z;
  5003.     else if (RL(dst) & S32) SET_S;
  5004. }
  5005.  
  5006. /******************************************
  5007.  rsvd9d
  5008.  flags:  ------
  5009.  ******************************************/
  5010. static void Z9D_imm8(void)
  5011. {
  5012.     GET_IMM8(0);
  5013.     LOG(("Z8K#%d %04x: rsvd9d $%02x\n", cpu_getactivecpu(), PC, imm8));
  5014.     if (FCW & F_EPU) {
  5015.         /* Z8001 EPU code goes here */
  5016.         (void)imm8;
  5017.     }
  5018. }
  5019.  
  5020. /******************************************
  5021.  ret     cc
  5022.  flags:  ------
  5023.  ******************************************/
  5024. static void Z9E_0000_cccc(void)
  5025. {
  5026.     GET_CCC(OP0,NIB3);
  5027.     switch (cc) {
  5028.         case  0: if (CC0) PC = POPW( SP ); break;
  5029.         case  1: if (CC1) PC = POPW( SP ); break;
  5030.         case  2: if (CC2) PC = POPW( SP ); break;
  5031.         case  3: if (CC3) PC = POPW( SP ); break;
  5032.         case  4: if (CC4) PC = POPW( SP ); break;
  5033.         case  5: if (CC5) PC = POPW( SP ); break;
  5034.         case  6: if (CC6) PC = POPW( SP ); break;
  5035.         case  7: if (CC7) PC = POPW( SP ); break;
  5036.         case  8: if (CC8) PC = POPW( SP ); break;
  5037.         case  9: if (CC9) PC = POPW( SP ); break;
  5038.         case 10: if (CCA) PC = POPW( SP ); break;
  5039.         case 11: if (CCB) PC = POPW( SP ); break;
  5040.         case 12: if (CCC) PC = POPW( SP ); break;
  5041.         case 13: if (CCD) PC = POPW( SP ); break;
  5042.         case 14: if (CCE) PC = POPW( SP ); break;
  5043.         case 15: if (CCF) PC = POPW( SP ); break;
  5044.     }
  5045.     change_pc16bew(PC);
  5046. }
  5047.  
  5048. /******************************************
  5049.  rsvd9f
  5050.  flags:  ------
  5051.  ******************************************/
  5052. static void Z9F_imm8(void)
  5053. {
  5054.     GET_IMM8(0);
  5055.     LOG(("Z8K#%d %04x: rsvd9f $%02x\n", cpu_getactivecpu(), PC, imm8));
  5056.     if (FCW & F_EPU) {
  5057.         /* Z8001 EPU code goes here */
  5058.         (void)imm8;
  5059.     }
  5060. }
  5061.  
  5062. /******************************************
  5063.  ldb     rbd,rbs
  5064.  flags:  ------
  5065.  ******************************************/
  5066. static void ZA0_ssss_dddd(void)
  5067. {
  5068.     GET_DST(OP0,NIB3);
  5069.     GET_SRC(OP0,NIB2);
  5070.     RB(dst) = RB(src);
  5071. }
  5072.  
  5073. /******************************************
  5074.  ld      rd,rs
  5075.  flags:  ------
  5076.  ******************************************/
  5077. static void ZA1_ssss_dddd(void)
  5078. {
  5079.     GET_DST(OP0,NIB3);
  5080.     GET_SRC(OP0,NIB2);
  5081.     RW(dst) = RW(src);
  5082. }
  5083.  
  5084. /******************************************
  5085.  resb     rbd,imm4
  5086.  flags:  ------
  5087.  ******************************************/
  5088. static void ZA2_dddd_imm4(void)
  5089. {
  5090.     GET_BIT(OP0);
  5091.     GET_DST(OP0,NIB2);
  5092.     RB(dst) &= ~bit;
  5093. }
  5094.  
  5095. /******************************************
  5096.  res     rd,imm4
  5097.  flags:  ------
  5098.  ******************************************/
  5099. static void ZA3_dddd_imm4(void)
  5100. {
  5101.     GET_BIT(OP0);
  5102.     GET_DST(OP0,NIB2);
  5103.     RW(dst) &= ~bit;
  5104. }
  5105.  
  5106. /******************************************
  5107.  setb     rbd,imm4
  5108.  flags:  ------
  5109.  ******************************************/
  5110. static void ZA4_dddd_imm4(void)
  5111. {
  5112.     GET_BIT(OP0);
  5113.     GET_DST(OP0,NIB2);
  5114.     RB(dst) |= bit;
  5115. }
  5116.  
  5117. /******************************************
  5118.  set     rd,imm4
  5119.  flags:  ------
  5120.  ******************************************/
  5121. static void ZA5_dddd_imm4(void)
  5122. {
  5123.     GET_BIT(OP0);
  5124.     GET_DST(OP0,NIB2);
  5125.     RW(dst) |= bit;
  5126. }
  5127.  
  5128. /******************************************
  5129.  bitb     rbd,imm4
  5130.  flags:  -Z----
  5131.  ******************************************/
  5132. static void ZA6_dddd_imm4(void)
  5133. {
  5134.     GET_BIT(OP0);
  5135.     GET_DST(OP0,NIB2);
  5136.     if (RB(dst) & bit) CLR_Z; else SET_Z;
  5137. }
  5138.  
  5139. /******************************************
  5140.  bit     rd,imm4
  5141.  flags:  -Z----
  5142.  ******************************************/
  5143. static void ZA7_dddd_imm4(void)
  5144. {
  5145.     GET_BIT(OP0);
  5146.     GET_DST(OP0,NIB2);
  5147.     if (RW(dst) & bit) CLR_Z; else SET_Z;
  5148. }
  5149.  
  5150. /******************************************
  5151.  incb     rbd,imm4m1
  5152.  flags:  -ZSV--
  5153.  ******************************************/
  5154. static void ZA8_dddd_imm4m1(void)
  5155. {
  5156.     GET_I4M1(OP0,NIB3);
  5157.     GET_DST(OP0,NIB2);
  5158.     RB(dst) = INCB( RB(dst), i4p1);
  5159. }
  5160.  
  5161. /******************************************
  5162.  inc     rd,imm4m1
  5163.  flags:  -ZSV--
  5164.  ******************************************/
  5165. static void ZA9_dddd_imm4m1(void)
  5166. {
  5167.     GET_I4M1(OP0,NIB3);
  5168.     GET_DST(OP0,NIB2);
  5169.     RW(dst) = INCW( RW(dst), i4p1 );
  5170. }
  5171.  
  5172. /******************************************
  5173.  decb     rbd,imm4m1
  5174.  flags:  -ZSV--
  5175.  ******************************************/
  5176. static void ZAA_dddd_imm4m1(void)
  5177. {
  5178.     GET_I4M1(OP0,NIB3);
  5179.     GET_DST(OP0,NIB2);
  5180.     RB(dst) = DECB( RB(dst), i4p1 );
  5181. }
  5182.  
  5183. /******************************************
  5184.  dec     rd,imm4m1
  5185.  flags:  -ZSV--
  5186.  ******************************************/
  5187. static void ZAB_dddd_imm4m1(void)
  5188. {
  5189.     GET_I4M1(OP0,NIB3);
  5190.     GET_DST(OP0,NIB2);
  5191.     RW(dst) = DECW( RW(dst), i4p1 );
  5192. }
  5193.  
  5194. /******************************************
  5195.  exb     rbd,rbs
  5196.  flags:  ------
  5197.  ******************************************/
  5198. static void ZAC_ssss_dddd(void)
  5199. {
  5200.     GET_DST(OP0,NIB3);
  5201.     GET_SRC(OP0,NIB2);
  5202.     UINT8 tmp = RB(src);
  5203.     RB(src) = RB(dst);
  5204.     RB(dst) = tmp;
  5205. }
  5206.  
  5207. /******************************************
  5208.  ex      rd,rs
  5209.  flags:  ------
  5210.  ******************************************/
  5211. static void ZAD_ssss_dddd(void)
  5212. {
  5213.     GET_DST(OP0,NIB3);
  5214.     GET_SRC(OP0,NIB2);
  5215.     UINT16 tmp = RW(src);
  5216.     RW(src) = RW(dst);
  5217.     RW(dst) = tmp;
  5218. }
  5219.  
  5220. /******************************************
  5221.  tccb     cc,rbd
  5222.  flags:  ------
  5223.  ******************************************/
  5224. static void ZAE_dddd_cccc(void)
  5225. {
  5226.     GET_CCC(OP0,NIB3);
  5227.     GET_DST(OP0,NIB2);
  5228.     UINT8 tmp = RB(dst) & ~1;
  5229.     switch (cc) {
  5230.         case  0: if (CC0) tmp |= 1; break;
  5231.         case  1: if (CC1) tmp |= 1; break;
  5232.         case  2: if (CC2) tmp |= 1; break;
  5233.         case  3: if (CC3) tmp |= 1; break;
  5234.         case  4: if (CC4) tmp |= 1; break;
  5235.         case  5: if (CC5) tmp |= 1; break;
  5236.         case  6: if (CC6) tmp |= 1; break;
  5237.         case  7: if (CC7) tmp |= 1; break;
  5238.         case  8: if (CC8) tmp |= 1; break;
  5239.         case  9: if (CC9) tmp |= 1; break;
  5240.         case 10: if (CCA) tmp |= 1; break;
  5241.         case 11: if (CCB) tmp |= 1; break;
  5242.         case 12: if (CCC) tmp |= 1; break;
  5243.         case 13: if (CCD) tmp |= 1; break;
  5244.         case 14: if (CCE) tmp |= 1; break;
  5245.         case 15: if (CCF) tmp |= 1; break;
  5246.     }
  5247.     RB(dst) = tmp;
  5248. }
  5249.  
  5250. /******************************************
  5251.  tcc     cc,rd
  5252.  flags:  ------
  5253.  ******************************************/
  5254. static void ZAF_dddd_cccc(void)
  5255. {
  5256.     GET_CCC(OP0,NIB3);
  5257.     GET_DST(OP0,NIB2);
  5258.     UINT16 tmp = RW(dst) & ~1;
  5259.     switch (cc) {
  5260.         case  0: if (CC0) tmp |= 1; break;
  5261.         case  1: if (CC1) tmp |= 1; break;
  5262.         case  2: if (CC2) tmp |= 1; break;
  5263.         case  3: if (CC3) tmp |= 1; break;
  5264.         case  4: if (CC4) tmp |= 1; break;
  5265.         case  5: if (CC5) tmp |= 1; break;
  5266.         case  6: if (CC6) tmp |= 1; break;
  5267.         case  7: if (CC7) tmp |= 1; break;
  5268.         case  8: if (CC8) tmp |= 1; break;
  5269.         case  9: if (CC9) tmp |= 1; break;
  5270.         case 10: if (CCA) tmp |= 1; break;
  5271.         case 11: if (CCB) tmp |= 1; break;
  5272.         case 12: if (CCC) tmp |= 1; break;
  5273.         case 13: if (CCD) tmp |= 1; break;
  5274.         case 14: if (CCE) tmp |= 1; break;
  5275.         case 15: if (CCF) tmp |= 1; break;
  5276.     }
  5277.     RW(dst) = tmp;
  5278. }
  5279.  
  5280. /******************************************
  5281.  dab     rbd
  5282.  flags:  CZS---
  5283.  ******************************************/
  5284. static void ZB0_dddd_0000(void)
  5285. {
  5286.     GET_DST(OP0,NIB2);
  5287.     UINT8 result;
  5288.     UINT16 idx = RB(dst);
  5289.     if (FCW & F_C)    idx |= 0x100;
  5290.     if (FCW & F_H)    idx |= 0x200;
  5291.     if (FCW & F_DA) idx |= 0x400;
  5292.     result = Z8000_dab[idx];
  5293.     CLR_CZS;
  5294.     CHK_XXXB_ZS;
  5295.     if (Z8000_dab[idx] & 0x100) SET_C;
  5296.     RB(dst) = result;
  5297. }
  5298.  
  5299. /******************************************
  5300.  extsb     rd
  5301.  flags:  ------
  5302.  ******************************************/
  5303. static void ZB1_dddd_0000(void)
  5304. {
  5305.     GET_DST(OP0,NIB2);
  5306.     RW(dst) = (RW(dst) & 0xff) | ((RW(dst) & S08) ? 0xff00 : 0x0000);
  5307. }
  5308.  
  5309. /******************************************
  5310.  extsl     rqd
  5311.  flags:  ------
  5312.  ******************************************/
  5313. static void ZB1_dddd_0111(void)
  5314. {
  5315.     GET_DST(OP0,NIB2);
  5316.     RQ(dst) = COMBINE_U64_U32_U32( (RQ(dst) & S32) ?
  5317.         0xfffffffful : 0, LO32_U32_U64(RQ(dst)));
  5318. }
  5319.  
  5320. /******************************************
  5321.  exts     rrd
  5322.  flags:  ------
  5323.  ******************************************/
  5324. static void ZB1_dddd_1010(void)
  5325. {
  5326.     GET_DST(OP0,NIB2);
  5327.     RL(dst) = (RL(dst) & 0xffff) | ((RL(dst) & S16) ?
  5328.         0xffff0000ul : 0x00000000ul);
  5329. }
  5330.  
  5331. /******************************************
  5332.  sllb     rbd,imm8
  5333.  flags:  CZS---
  5334.  srlb     rbd,imm8
  5335.  flags:  CZSV--
  5336.  ******************************************/
  5337. static void ZB2_dddd_0001_imm8(void)
  5338. {
  5339.     GET_DST(OP0,NIB2);
  5340.     GET_IMM16(OP1);
  5341.     if (imm16 & S16)
  5342.         RB(dst) = SRLB( RB(dst), -(INT16)imm16 );
  5343.     else
  5344.         RB(dst) = SLLB( RB(dst), imm16 );
  5345. }
  5346.  
  5347. /******************************************
  5348.  sdlb     rbd,rs
  5349.  flags:  CZS---
  5350.  ******************************************/
  5351. static void ZB2_dddd_0011_0000_ssss_0000_0000(void)
  5352. {
  5353.     GET_DST(OP0,NIB2);
  5354.     GET_SRC(OP1,NIB1);
  5355.     RB(dst) = SRLB( RB(dst), (INT8)RW(src) );
  5356. }
  5357.  
  5358. /******************************************
  5359.  rlb     rbd,imm1or2
  5360.  flags:  CZSV--
  5361.  ******************************************/
  5362. static void ZB2_dddd_00I0(void)
  5363. {
  5364.     GET_DST(OP0,NIB2);
  5365.     GET_IMM1(OP0,NIB3);
  5366.     RB(dst) = RLB( RB(dst), imm1 );
  5367. }
  5368.  
  5369. /******************************************
  5370.  rrb     rbd,imm1or2
  5371.  flags:  CZSV--
  5372.  ******************************************/
  5373. static void ZB2_dddd_01I0(void)
  5374. {
  5375.     GET_DST(OP0,NIB2);
  5376.     GET_IMM1(OP0,NIB3);
  5377.     RB(dst) = RRB( RB(dst), imm1 );
  5378. }
  5379.  
  5380. /******************************************
  5381.  slab     rbd,imm8
  5382.  flags:  CZSV--
  5383.  srab     rbd,imm8
  5384.  flags:  CZSV--
  5385.  ******************************************/
  5386. static void ZB2_dddd_1001_imm8(void)
  5387. {
  5388.     GET_DST(OP0,NIB2);
  5389.     GET_IMM16(OP1);
  5390.     if (imm16 & S16)
  5391.         RB(dst) = SRAB( RB(dst), -(INT16)imm16 );
  5392.     else
  5393.         RB(dst) = SLAB( RB(dst), imm16 );
  5394. }
  5395.  
  5396. /******************************************
  5397.  sdab     rbd,rs
  5398.  flags:  CZSV--
  5399.  ******************************************/
  5400. static void ZB2_dddd_1011_0000_ssss_0000_0000(void)
  5401. {
  5402.     GET_DST(OP0,NIB2);
  5403.     GET_SRC(OP1,NIB1);
  5404.     RB(dst) = SDAB( RB(dst), (INT8) RW(src) );
  5405. }
  5406.  
  5407. /******************************************
  5408.  rlcb     rbd,imm1or2
  5409.  flags:  -Z----
  5410.  ******************************************/
  5411. static void ZB2_dddd_10I0(void)
  5412. {
  5413.     GET_DST(OP0,NIB2);
  5414.     GET_IMM1(OP0,NIB3);
  5415.     RB(dst) = RLCB( RB(dst), imm1 );
  5416. }
  5417.  
  5418. /******************************************
  5419.  rrcb     rbd,imm1or2
  5420.  flags:  -Z----
  5421.  ******************************************/
  5422. static void ZB2_dddd_11I0(void)
  5423. {
  5424.     GET_DST(OP0,NIB2);
  5425.     GET_IMM1(OP0,NIB3);
  5426.     RB(dst) = RRCB( RB(dst), imm1 );
  5427. }
  5428.  
  5429. /******************************************
  5430.  sll     rd,imm8
  5431.  flags:  CZS---
  5432.  srl     rd,imm8
  5433.  flags:  CZSV--
  5434.  ******************************************/
  5435. static void ZB3_dddd_0001_imm8(void)
  5436. {
  5437.     GET_DST(OP0,NIB2);
  5438.     GET_IMM16(OP1);
  5439.     if (imm16 & S16)
  5440.         RW(dst) = SRLW( RW(dst), -(INT16)imm16 );
  5441.     else
  5442.         RW(dst) = SLLW( RW(dst), imm16 );
  5443. }
  5444.  
  5445. /******************************************
  5446.  sdl     rd,rs
  5447.  flags:  CZS---
  5448.  ******************************************/
  5449. static void ZB3_dddd_0011_0000_ssss_0000_0000(void)
  5450. {
  5451.     GET_DST(OP0,NIB2);
  5452.     GET_SRC(OP1,NIB1);
  5453.     RW(dst) = SDLW( RW(dst), (INT8)RW(src) );
  5454. }
  5455.  
  5456. /******************************************
  5457.  rl      rd,imm1or2
  5458.  flags:  CZSV--
  5459.  ******************************************/
  5460. static void ZB3_dddd_00I0(void)
  5461. {
  5462.     GET_DST(OP0,NIB2);
  5463.     GET_IMM1(OP0,NIB3);
  5464.     RW(dst) = RLW( RW(dst), imm1 );
  5465. }
  5466.  
  5467. /******************************************
  5468.  slll     rrd,imm8
  5469.  flags:  CZS---
  5470.  srll     rrd,imm8
  5471.  flags:  CZSV--
  5472.  ******************************************/
  5473. static void ZB3_dddd_0101_imm8(void)
  5474. {
  5475.     GET_DST(OP0,NIB2);
  5476.     GET_IMM16(OP1);
  5477.     if (imm16 & S16)
  5478.         RL(dst) = SRLL( RL(dst), -(INT16)imm16 );
  5479.     else
  5480.         RL(dst) = SLLL( RL(dst), imm16 );
  5481. }
  5482.  
  5483. /******************************************
  5484.  sdll     rrd,rs
  5485.  flags:  CZS---
  5486.  ******************************************/
  5487. static void ZB3_dddd_0111_0000_ssss_0000_0000(void)
  5488. {
  5489.     GET_DST(OP0,NIB2);
  5490.     GET_SRC(OP1,NIB1);
  5491.     RL(dst) = SDLL( RL(dst), RW(src) & 0xff );
  5492. }
  5493.  
  5494. /******************************************
  5495.  rr      rd,imm1or2
  5496.  flags:  CZSV--
  5497.  ******************************************/
  5498. static void ZB3_dddd_01I0(void)
  5499. {
  5500.     GET_DST(OP0,NIB2);
  5501.     GET_IMM1(OP0,NIB3);
  5502.     RW(dst) = RRW( RW(dst), imm1 );
  5503. }
  5504.  
  5505. /******************************************
  5506.  sla     rd,imm8
  5507.  flags:  CZSV--
  5508.  sra     rd,imm8
  5509.  flags:  CZSV--
  5510.  ******************************************/
  5511. static void ZB3_dddd_1001_imm8(void)
  5512. {
  5513.     GET_DST(OP0,NIB2);
  5514.     GET_IMM16(OP1);
  5515.     if (imm16 & S16)
  5516.         RW(dst) = SRAW( RW(dst), -(INT16)imm16 );
  5517.     else
  5518.         RW(dst) = SLAW( RW(dst), imm16 );
  5519. }
  5520.  
  5521. /******************************************
  5522.  sda     rd,rs
  5523.  flags:  CZSV--
  5524.  ******************************************/
  5525. static void ZB3_dddd_1011_0000_ssss_0000_0000(void)
  5526. {
  5527.     GET_DST(OP0,NIB2);
  5528.     GET_SRC(OP1,NIB1);
  5529.     RW(dst) = SDAW( RW(dst), (INT8)RW(src) );
  5530. }
  5531.  
  5532. /******************************************
  5533.  rlc     rd,imm1or2
  5534.  flags:  CZSV--
  5535.  ******************************************/
  5536. static void ZB3_dddd_10I0(void)
  5537. {
  5538.     GET_DST(OP0,NIB2);
  5539.     GET_IMM1(OP0,NIB3);
  5540.     RW(dst) = RLCW( RW(dst), imm1 );
  5541. }
  5542.  
  5543. /******************************************
  5544.  slal     rrd,imm8
  5545.  flags:  CZSV--
  5546.  sral     rrd,imm8
  5547.  flags:  CZSV--
  5548.  ******************************************/
  5549. static void ZB3_dddd_1101_imm8(void)
  5550. {
  5551.     GET_DST(OP0,NIB2);
  5552.     GET_IMM16(OP1);
  5553.     if (imm16 & S16)
  5554.         RL(dst) = SRAL( RL(dst), -(INT16)imm16 );
  5555.     else
  5556.         RL(dst) = SLAL( RL(dst), imm16 );
  5557. }
  5558.  
  5559. /******************************************
  5560.  sdal     rrd,rs
  5561.  flags:  CZSV--
  5562.  ******************************************/
  5563. static void ZB3_dddd_1111_0000_ssss_0000_0000(void)
  5564. {
  5565.     GET_DST(OP0,NIB2);
  5566.     GET_SRC(OP1,NIB1);
  5567.     RL(dst) = SDAL( RL(dst), RW(src) & 0xff );
  5568. }
  5569.  
  5570. /******************************************
  5571.  rrc     rd,imm1or2
  5572.  flags:  CZSV--
  5573.  ******************************************/
  5574. static void ZB3_dddd_11I0(void)
  5575. {
  5576.     GET_DST(OP0,NIB2);
  5577.     GET_IMM1(OP0,NIB3);
  5578.     RW(dst) = RRCW( RW(dst), imm1 );
  5579. }
  5580.  
  5581. /******************************************
  5582.  adcb     rbd,rbs
  5583.  flags:  CZSVDH
  5584.  ******************************************/
  5585. static void ZB4_ssss_dddd(void)
  5586. {
  5587.     GET_DST(OP0,NIB3);
  5588.     GET_SRC(OP0,NIB2);
  5589.     RB(dst) = ADCB( RB(dst), RB(src) );
  5590. }
  5591.  
  5592. /******************************************
  5593.  adc     rd,rs
  5594.  flags:  CZSV--
  5595.  ******************************************/
  5596. static void ZB5_ssss_dddd(void)
  5597. {
  5598.     GET_DST(OP0,NIB3);
  5599.     GET_SRC(OP0,NIB2);
  5600.     RW(dst) = ADCW( RW(dst), RW(src) );
  5601. }
  5602.  
  5603. /******************************************
  5604.  sbcb     rbd,rbs
  5605.  flags:  CZSVDH
  5606.  ******************************************/
  5607. static void ZB6_ssss_dddd(void)
  5608. {
  5609.     GET_DST(OP0,NIB3);
  5610.     GET_SRC(OP0,NIB2);
  5611.     RB(dst) = SBCB( RB(dst), RB(src) );
  5612. }
  5613.  
  5614. /******************************************
  5615.  sbc     rd,rs
  5616.  flags:  CZSV--
  5617.  ******************************************/
  5618. static void ZB7_ssss_dddd(void)
  5619. {
  5620.     GET_DST(OP0,NIB3);
  5621.     GET_SRC(OP0,NIB2);
  5622.     RW(dst) = SBCW( RW(dst), RW(src) );
  5623. }
  5624.  
  5625. /******************************************
  5626.  trtib     @rd,@rs,rr
  5627.  flags:  -ZSV--
  5628.  ******************************************/
  5629. static void ZB8_ddN0_0010_0000_rrrr_ssN0_0000(void)
  5630. {
  5631.     GET_DST(OP0,NIB2);
  5632.     GET_SRC(OP1,NIB2);
  5633.     GET_CNT(OP1,NIB1);
  5634.     UINT8 xlt = RDMEM_B( (UINT16)(RW(src) + RDMEM_B(RW(dst))) );
  5635.     RB(2) = xlt;
  5636.     if (xlt) CLR_Z; else SET_Z;
  5637.     RW(dst)++;
  5638.     if (--RW(cnt)) CLR_V; else SET_V;
  5639. }
  5640.  
  5641. /******************************************
  5642.  trtirb  @rd,@rs,rbr
  5643.  flags:  -ZSV--
  5644.  ******************************************/
  5645. static void ZB8_ddN0_0110_0000_rrrr_ssN0_1110(void)
  5646. {
  5647.     GET_DST(OP0,NIB2);
  5648.     GET_SRC(OP1,NIB2);
  5649.     GET_CNT(OP1,NIB1);
  5650.     UINT8 xlt = RDMEM_B( (UINT16)(RW(src) + RDMEM_B(RW(dst))) );
  5651.     RB(2) = xlt;
  5652.     if (xlt) CLR_Z; else SET_Z;
  5653.     RW(dst)++;
  5654.     if (--RW(cnt)) { CLR_V; PC -= 4; } else SET_V;
  5655. }
  5656.  
  5657. /******************************************
  5658.  trtdb     @rd,@rs,rbr
  5659.  flags:  -ZSV--
  5660.  ******************************************/
  5661. static void ZB8_ddN0_1010_0000_rrrr_ssN0_0000(void)
  5662. {
  5663.     GET_DST(OP0,NIB2);
  5664.     GET_SRC(OP1,NIB2);
  5665.     GET_CNT(OP1,NIB1);
  5666.     UINT8 xlt = RDMEM_B( (UINT16)(RW(src) + RDMEM_B(RW(dst))) );
  5667.     RB(2) = xlt;
  5668.     if (xlt) CLR_Z; else SET_Z;
  5669.     RW(dst)--;
  5670.     if (--RW(cnt)) CLR_V; else SET_V;
  5671. }
  5672.  
  5673. /******************************************
  5674.  trtdrb  @rd,@rs,rbr
  5675.  flags:  -ZSV--
  5676.  ******************************************/
  5677. static void ZB8_ddN0_1110_0000_rrrr_ssN0_1110(void)
  5678. {
  5679.     GET_DST(OP0,NIB2);
  5680.     GET_SRC(OP1,NIB2);
  5681.     GET_CNT(OP1,NIB1);
  5682.     UINT8 xlt = RDMEM_B( (UINT16)(RW(src) + RDMEM_B(RW(dst))) );
  5683.     RB(2) = xlt;
  5684.     if (xlt) CLR_Z; else SET_Z;
  5685.     RW(dst)--;
  5686.     if (--RW(cnt)) { CLR_V; PC -= 4; } else SET_V;
  5687. }
  5688.  
  5689. /******************************************
  5690.  trib     @rd,@rs,rbr
  5691.  flags:  -ZSV--
  5692.  ******************************************/
  5693. static void ZB8_ddN0_0000_0000_rrrr_ssN0_0000(void)
  5694. {
  5695.     GET_DST(OP0,NIB2);
  5696.     GET_SRC(OP1,NIB2);
  5697.     GET_CNT(OP1,NIB1);
  5698.     UINT8 xlt = RDMEM_B( (UINT16)(RW(src) + RDMEM_B(RW(dst))) );
  5699.     WRMEM_B( RW(dst), xlt );
  5700.     RW(dst)++;
  5701.     if (--RW(cnt)) CLR_V; else SET_V;
  5702. }
  5703.  
  5704. /******************************************
  5705.  trirb     @rd,@rs,rbr
  5706.  flags:  -ZSV--
  5707.  ******************************************/
  5708. static void ZB8_ddN0_0100_0000_rrrr_ssN0_0000(void)
  5709. {
  5710.     GET_DST(OP0,NIB2);
  5711.     GET_SRC(OP1,NIB2);
  5712.     GET_CNT(OP1,NIB1);
  5713.     UINT8 xlt = RDMEM_B( (UINT16)(RW(src) + RDMEM_B(RW(dst))) );
  5714.     WRMEM_B( RW(dst), xlt );
  5715.     RW(dst)++;
  5716.     if (--RW(cnt)) { CLR_V; PC -= 4; } else SET_V;
  5717. }
  5718.  
  5719. /******************************************
  5720.  trdb     @rd,@rs,rbr
  5721.  flags:  -ZSV--
  5722.  ******************************************/
  5723. static void ZB8_ddN0_1000_0000_rrrr_ssN0_0000(void)
  5724. {
  5725.     GET_DST(OP0,NIB2);
  5726.     GET_SRC(OP1,NIB2);
  5727.     GET_CNT(OP1,NIB1);
  5728.     UINT8 xlt = RDMEM_B( (UINT16)(RW(src) + RDMEM_B(RW(dst))) );
  5729.     WRMEM_B( RW(dst), xlt );
  5730.     RW(dst)--;
  5731.     if (--RW(cnt)) CLR_V; else SET_V;
  5732. }
  5733.  
  5734. /******************************************
  5735.  trdrb     @rd,@rs,rbr
  5736.  flags:  -ZSV--
  5737.  ******************************************/
  5738. static void ZB8_ddN0_1100_0000_rrrr_ssN0_0000(void)
  5739. {
  5740.     GET_DST(OP0,NIB2);
  5741.     GET_SRC(OP1,NIB2);
  5742.     GET_CNT(OP1,NIB1);
  5743.     UINT8 xlt = RDMEM_B( (UINT16)(RW(src) + RDMEM_B(RW(dst))) );
  5744.     WRMEM_B( RW(dst), xlt );
  5745.     RW(dst)--;
  5746.     if (--RW(cnt)) { CLR_V; PC -= 4; } else SET_V;
  5747. }
  5748.  
  5749. /******************************************
  5750.  rsvdb9
  5751.  flags:  ------
  5752.  ******************************************/
  5753. static void ZB9_imm8(void)
  5754. {
  5755.     GET_IMM8(0);
  5756.     LOG(("Z8K#%d %04x: rsvdb9 $%02x\n", cpu_getactivecpu(), PC, imm8));
  5757.     if (FCW & F_EPU) {
  5758.         /* Z8001 EPU code goes here */
  5759.         (void)imm8;
  5760.     }
  5761.     (void)imm8;
  5762. }
  5763.  
  5764. /******************************************
  5765.  cpib     rbd,@rs,rr,cc
  5766.  flags:  CZSV--
  5767.  ******************************************/
  5768. static void ZBA_ssN0_0000_0000_rrrr_dddd_cccc(void)
  5769. {
  5770.     GET_SRC(OP0,NIB2);
  5771.     GET_CCC(OP1,NIB3);
  5772.     GET_DST(OP1,NIB2);
  5773.     GET_CNT(OP1,NIB1);
  5774.     CPB( RB(dst), RDMEM_B(RW(src)) );
  5775.     switch (cc) {
  5776.         case  0: if (CC0) SET_Z; else CLR_Z; break;
  5777.         case  1: if (CC1) SET_Z; else CLR_Z; break;
  5778.         case  2: if (CC2) SET_Z; else CLR_Z; break;
  5779.         case  3: if (CC3) SET_Z; else CLR_Z; break;
  5780.         case  4: if (CC4) SET_Z; else CLR_Z; break;
  5781.         case  5: if (CC5) SET_Z; else CLR_Z; break;
  5782.         case  6: if (CC6) SET_Z; else CLR_Z; break;
  5783.         case  7: if (CC7) SET_Z; else CLR_Z; break;
  5784.         case  8: if (CC8) SET_Z; else CLR_Z; break;
  5785.         case  9: if (CC9) SET_Z; else CLR_Z; break;
  5786.         case 10: if (CCA) SET_Z; else CLR_Z; break;
  5787.         case 11: if (CCB) SET_Z; else CLR_Z; break;
  5788.         case 12: if (CCC) SET_Z; else CLR_Z; break;
  5789.         case 13: if (CCD) SET_Z; else CLR_Z; break;
  5790.         case 14: if (CCE) SET_Z; else CLR_Z; break;
  5791.         case 15: if (CCF) SET_Z; else CLR_Z; break;
  5792.     }
  5793.     RW(src)++;
  5794.     if (--RW(cnt)) CLR_V; else SET_V;
  5795. }
  5796.  
  5797. /******************************************
  5798.  ldib     @rd,@rs,rr
  5799.  ldibr     @rd,@rs,rr
  5800.  flags:  ---V--
  5801.  ******************************************/
  5802. static void ZBA_ssN0_0001_0000_rrrr_ddN0_x000(void)
  5803. {
  5804.     GET_SRC(OP0,NIB2);
  5805.     GET_CNT(OP1,NIB1);
  5806.     GET_DST(OP1,NIB2);
  5807.     GET_CCC(OP1,NIB3);    /* repeat? */
  5808.     WRMEM_B( RW(dst), RDMEM_B(RW(src)) );
  5809.     RW(dst)++;
  5810.     RW(src)++;
  5811.     if (--RW(cnt)) { CLR_V; if (cc == 0) PC -= 4; } else SET_V;
  5812. }
  5813.  
  5814. /******************************************
  5815.  cpsib     @rd,@rs,rr,cc
  5816.  flags:  CZSV--
  5817.  ******************************************/
  5818. static void ZBA_ssN0_0010_0000_rrrr_ddN0_cccc(void)
  5819. {
  5820.     GET_SRC(OP0,NIB2);
  5821.     GET_CCC(OP1,NIB3);
  5822.     GET_DST(OP1,NIB2);
  5823.     GET_CNT(OP1,NIB1);
  5824.     CPB( RDMEM_B(RW(dst)), RDMEM_B(RW(src)) );
  5825.     switch (cc) {
  5826.         case  0: if (CC0) SET_Z; else CLR_Z; break;
  5827.         case  1: if (CC1) SET_Z; else CLR_Z; break;
  5828.         case  2: if (CC2) SET_Z; else CLR_Z; break;
  5829.         case  3: if (CC3) SET_Z; else CLR_Z; break;
  5830.         case  4: if (CC4) SET_Z; else CLR_Z; break;
  5831.         case  5: if (CC5) SET_Z; else CLR_Z; break;
  5832.         case  6: if (CC6) SET_Z; else CLR_Z; break;
  5833.         case  7: if (CC7) SET_Z; else CLR_Z; break;
  5834.         case  8: if (CC8) SET_Z; else CLR_Z; break;
  5835.         case  9: if (CC9) SET_Z; else CLR_Z; break;
  5836.         case 10: if (CCA) SET_Z; else CLR_Z; break;
  5837.         case 11: if (CCB) SET_Z; else CLR_Z; break;
  5838.         case 12: if (CCC) SET_Z; else CLR_Z; break;
  5839.         case 13: if (CCD) SET_Z; else CLR_Z; break;
  5840.         case 14: if (CCE) SET_Z; else CLR_Z; break;
  5841.         case 15: if (CCF) SET_Z; else CLR_Z; break;
  5842.     }
  5843.     RW(dst)++;
  5844.     RW(src)++;
  5845.     if (--RW(cnt)) { CLR_V; if (!(FCW & F_Z)) PC -= 4; } else SET_V;
  5846. }
  5847.  
  5848. /******************************************
  5849.  cpirb     rbd,@rs,rr,cc
  5850.  flags:  CZSV--
  5851.  ******************************************/
  5852. static void ZBA_ssN0_0100_0000_rrrr_dddd_cccc(void)
  5853. {
  5854.     GET_SRC(OP0,NIB2);
  5855.     GET_CCC(OP1,NIB3);
  5856.     GET_DST(OP1,NIB2);
  5857.     GET_CNT(OP1,NIB1);
  5858.     CPB( RB(dst), RDMEM_B(RW(src)) );
  5859.     switch (cc) {
  5860.         case  0: if (CC0) SET_Z; else CLR_Z; break;
  5861.         case  1: if (CC1) SET_Z; else CLR_Z; break;
  5862.         case  2: if (CC2) SET_Z; else CLR_Z; break;
  5863.         case  3: if (CC3) SET_Z; else CLR_Z; break;
  5864.         case  4: if (CC4) SET_Z; else CLR_Z; break;
  5865.         case  5: if (CC5) SET_Z; else CLR_Z; break;
  5866.         case  6: if (CC6) SET_Z; else CLR_Z; break;
  5867.         case  7: if (CC7) SET_Z; else CLR_Z; break;
  5868.         case  8: if (CC8) SET_Z; else CLR_Z; break;
  5869.         case  9: if (CC9) SET_Z; else CLR_Z; break;
  5870.         case 10: if (CCA) SET_Z; else CLR_Z; break;
  5871.         case 11: if (CCB) SET_Z; else CLR_Z; break;
  5872.         case 12: if (CCC) SET_Z; else CLR_Z; break;
  5873.         case 13: if (CCD) SET_Z; else CLR_Z; break;
  5874.         case 14: if (CCE) SET_Z; else CLR_Z; break;
  5875.         case 15: if (CCF) SET_Z; else CLR_Z; break;
  5876.     }
  5877.     RW(src)++;
  5878.     if (--RW(cnt)) { CLR_V; if (!(FCW & F_Z)) PC -= 4; } else SET_V;
  5879. }
  5880.  
  5881. /******************************************
  5882.  cpsirb  @rd,@rs,rr,cc
  5883.  flags:  CZSV--
  5884.  ******************************************/
  5885. static void ZBA_ssN0_0110_0000_rrrr_ddN0_cccc(void)
  5886. {
  5887.     GET_SRC(OP0,NIB2);
  5888.     GET_CCC(OP1,NIB3);
  5889.     GET_DST(OP1,NIB2);
  5890.     GET_CNT(OP1,NIB1);
  5891.     CPB( RDMEM_B(RW(dst)), RDMEM_B(RW(src)) );
  5892.     switch (cc) {
  5893.         case  0: if (CC0) SET_Z; else CLR_Z; break;
  5894.         case  1: if (CC1) SET_Z; else CLR_Z; break;
  5895.         case  2: if (CC2) SET_Z; else CLR_Z; break;
  5896.         case  3: if (CC3) SET_Z; else CLR_Z; break;
  5897.         case  4: if (CC4) SET_Z; else CLR_Z; break;
  5898.         case  5: if (CC5) SET_Z; else CLR_Z; break;
  5899.         case  6: if (CC6) SET_Z; else CLR_Z; break;
  5900.         case  7: if (CC7) SET_Z; else CLR_Z; break;
  5901.         case  8: if (CC8) SET_Z; else CLR_Z; break;
  5902.         case  9: if (CC9) SET_Z; else CLR_Z; break;
  5903.         case 10: if (CCA) SET_Z; else CLR_Z; break;
  5904.         case 11: if (CCB) SET_Z; else CLR_Z; break;
  5905.         case 12: if (CCC) SET_Z; else CLR_Z; break;
  5906.         case 13: if (CCD) SET_Z; else CLR_Z; break;
  5907.         case 14: if (CCE) SET_Z; else CLR_Z; break;
  5908.         case 15: if (CCF) SET_Z; else CLR_Z; break;
  5909.     }
  5910.     RW(dst)++;
  5911.     RW(src)++;
  5912.     if (--RW(cnt)) { CLR_V; if (!(FCW & F_Z)) PC -= 4; } else SET_V;
  5913. }
  5914.  
  5915. /******************************************
  5916.  cpdb     rbd,@rs,rr,cc
  5917.  flags:  CZSV--
  5918.  ******************************************/
  5919. static void ZBA_ssN0_1000_0000_rrrr_dddd_cccc(void)
  5920. {
  5921.     GET_SRC(OP0,NIB2);
  5922.     GET_CCC(OP1,NIB3);
  5923.     GET_DST(OP1,NIB2);
  5924.     GET_CNT(OP1,NIB1);
  5925.     CPB( RB(dst), RDMEM_B(RW(src)) );
  5926.     switch (cc) {
  5927.         case  0: if (CC0) SET_Z; else CLR_Z; break;
  5928.         case  1: if (CC1) SET_Z; else CLR_Z; break;
  5929.         case  2: if (CC2) SET_Z; else CLR_Z; break;
  5930.         case  3: if (CC3) SET_Z; else CLR_Z; break;
  5931.         case  4: if (CC4) SET_Z; else CLR_Z; break;
  5932.         case  5: if (CC5) SET_Z; else CLR_Z; break;
  5933.         case  6: if (CC6) SET_Z; else CLR_Z; break;
  5934.         case  7: if (CC7) SET_Z; else CLR_Z; break;
  5935.         case  8: if (CC8) SET_Z; else CLR_Z; break;
  5936.         case  9: if (CC9) SET_Z; else CLR_Z; break;
  5937.         case 10: if (CCA) SET_Z; else CLR_Z; break;
  5938.         case 11: if (CCB) SET_Z; else CLR_Z; break;
  5939.         case 12: if (CCC) SET_Z; else CLR_Z; break;
  5940.         case 13: if (CCD) SET_Z; else CLR_Z; break;
  5941.         case 14: if (CCE) SET_Z; else CLR_Z; break;
  5942.         case 15: if (CCF) SET_Z; else CLR_Z; break;
  5943.     }
  5944.     RW(src)--;
  5945.     if (--RW(cnt)) CLR_V; else SET_V;
  5946. }
  5947.  
  5948. /******************************************
  5949.  lddb     @rs,@rd,rr
  5950.  lddbr     @rs,@rd,rr
  5951.  flags:  ---V--
  5952.  ******************************************/
  5953. static void ZBA_ssN0_1001_0000_rrrr_ddN0_x000(void)
  5954. {
  5955.     GET_SRC(OP0,NIB2);
  5956.     GET_CNT(OP1,NIB1);
  5957.     GET_DST(OP1,NIB2);
  5958.     GET_CCC(OP1,NIB3);
  5959.     WRMEM_B( RW(dst), RDMEM_B(RW(src)) );
  5960.     RW(dst)--;
  5961.     RW(src)--;
  5962.     if (--RW(cnt)) { CLR_V; if (cc == 0) PC -= 4; } else SET_V;
  5963. }
  5964.  
  5965. /******************************************
  5966.  cpsdb     @rd,@rs,rr,cc
  5967.  flags:  CZSV--
  5968.  ******************************************/
  5969. static void ZBA_ssN0_1010_0000_rrrr_ddN0_cccc(void)
  5970. {
  5971.     GET_SRC(OP0,NIB2);
  5972.     GET_CCC(OP1,NIB3);
  5973.     GET_DST(OP1,NIB2);
  5974.     GET_CNT(OP1,NIB1);
  5975.     CPB( RDMEM_B(RW(dst)), RDMEM_B(RW(src)) );
  5976.     switch (cc) {
  5977.         case  0: if (CC0) SET_Z; else CLR_Z; break;
  5978.         case  1: if (CC1) SET_Z; else CLR_Z; break;
  5979.         case  2: if (CC2) SET_Z; else CLR_Z; break;
  5980.         case  3: if (CC3) SET_Z; else CLR_Z; break;
  5981.         case  4: if (CC4) SET_Z; else CLR_Z; break;
  5982.         case  5: if (CC5) SET_Z; else CLR_Z; break;
  5983.         case  6: if (CC6) SET_Z; else CLR_Z; break;
  5984.         case  7: if (CC7) SET_Z; else CLR_Z; break;
  5985.         case  8: if (CC8) SET_Z; else CLR_Z; break;
  5986.         case  9: if (CC9) SET_Z; else CLR_Z; break;
  5987.         case 10: if (CCA) SET_Z; else CLR_Z; break;
  5988.         case 11: if (CCB) SET_Z; else CLR_Z; break;
  5989.         case 12: if (CCC) SET_Z; else CLR_Z; break;
  5990.         case 13: if (CCD) SET_Z; else CLR_Z; break;
  5991.         case 14: if (CCE) SET_Z; else CLR_Z; break;
  5992.         case 15: if (CCF) SET_Z; else CLR_Z; break;
  5993.     }
  5994.     RW(dst)--;
  5995.     RW(src)--;
  5996.     if (--RW(cnt)) CLR_V; else SET_V;
  5997. }
  5998.  
  5999. /******************************************
  6000.  cpdrb     rbd,@rs,rr,cc
  6001.  flags:  CZSV--
  6002.  ******************************************/
  6003. static void ZBA_ssN0_1100_0000_rrrr_dddd_cccc(void)
  6004. {
  6005.     GET_SRC(OP0,NIB2);
  6006.     GET_CCC(OP1,NIB3);
  6007.     GET_DST(OP1,NIB2);
  6008.     GET_CNT(OP1,NIB1);
  6009.     CPB( RB(dst), RDMEM_B(RW(src)) );
  6010.     switch (cc) {
  6011.         case  0: if (CC0) SET_Z; else CLR_Z; break;
  6012.         case  1: if (CC1) SET_Z; else CLR_Z; break;
  6013.         case  2: if (CC2) SET_Z; else CLR_Z; break;
  6014.         case  3: if (CC3) SET_Z; else CLR_Z; break;
  6015.         case  4: if (CC4) SET_Z; else CLR_Z; break;
  6016.         case  5: if (CC5) SET_Z; else CLR_Z; break;
  6017.         case  6: if (CC6) SET_Z; else CLR_Z; break;
  6018.         case  7: if (CC7) SET_Z; else CLR_Z; break;
  6019.         case  8: if (CC8) SET_Z; else CLR_Z; break;
  6020.         case  9: if (CC9) SET_Z; else CLR_Z; break;
  6021.         case 10: if (CCA) SET_Z; else CLR_Z; break;
  6022.         case 11: if (CCB) SET_Z; else CLR_Z; break;
  6023.         case 12: if (CCC) SET_Z; else CLR_Z; break;
  6024.         case 13: if (CCD) SET_Z; else CLR_Z; break;
  6025.         case 14: if (CCE) SET_Z; else CLR_Z; break;
  6026.         case 15: if (CCF) SET_Z; else CLR_Z; break;
  6027.     }
  6028.     RW(src)--;
  6029.     if (--RW(cnt)) { CLR_V; if (!(FCW & F_Z)) PC -= 4; } else SET_V;
  6030. }
  6031.  
  6032. /******************************************
  6033.  cpsdrb  @rd,@rs,rr,cc
  6034.  flags:  CZSV--
  6035.  ******************************************/
  6036. static void ZBA_ssN0_1110_0000_rrrr_ddN0_cccc(void)
  6037. {
  6038.     GET_SRC(OP0,NIB2);
  6039.     GET_CCC(OP1,NIB3);
  6040.     GET_DST(OP1,NIB2);
  6041.     GET_CNT(OP1,NIB1);
  6042.     CPB( RDMEM_B(RW(dst)), RDMEM_B(RW(src)) );
  6043.     switch (cc) {
  6044.         case  0: if (CC0) SET_Z; else CLR_Z; break;
  6045.         case  1: if (CC1) SET_Z; else CLR_Z; break;
  6046.         case  2: if (CC2) SET_Z; else CLR_Z; break;
  6047.         case  3: if (CC3) SET_Z; else CLR_Z; break;
  6048.         case  4: if (CC4) SET_Z; else CLR_Z; break;
  6049.         case  5: if (CC5) SET_Z; else CLR_Z; break;
  6050.         case  6: if (CC6) SET_Z; else CLR_Z; break;
  6051.         case  7: if (CC7) SET_Z; else CLR_Z; break;
  6052.         case  8: if (CC8) SET_Z; else CLR_Z; break;
  6053.         case  9: if (CC9) SET_Z; else CLR_Z; break;
  6054.         case 10: if (CCA) SET_Z; else CLR_Z; break;
  6055.         case 11: if (CCB) SET_Z; else CLR_Z; break;
  6056.         case 12: if (CCC) SET_Z; else CLR_Z; break;
  6057.         case 13: if (CCD) SET_Z; else CLR_Z; break;
  6058.         case 14: if (CCE) SET_Z; else CLR_Z; break;
  6059.         case 15: if (CCF) SET_Z; else CLR_Z; break;
  6060.     }
  6061.     RW(dst)--;
  6062.     RW(src)--;
  6063.     if (--RW(cnt)) { CLR_V; if (!(FCW & F_Z)) PC -= 4; } else SET_V;
  6064. }
  6065.  
  6066. /******************************************
  6067.  cpi     rd,@rs,rr,cc
  6068.  flags:  CZSV--
  6069.  ******************************************/
  6070. static void ZBB_ssN0_0000_0000_rrrr_dddd_cccc(void)
  6071. {
  6072.     GET_SRC(OP0,NIB2);
  6073.     GET_CCC(OP1,NIB3);
  6074.     GET_DST(OP1,NIB2);
  6075.     GET_CNT(OP1,NIB1);
  6076.     CPW( RW(dst), RDMEM_W(RW(src)) );
  6077.     switch (cc) {
  6078.         case  0: if (CC0) SET_Z; else CLR_Z; break;
  6079.         case  1: if (CC1) SET_Z; else CLR_Z; break;
  6080.         case  2: if (CC2) SET_Z; else CLR_Z; break;
  6081.         case  3: if (CC3) SET_Z; else CLR_Z; break;
  6082.         case  4: if (CC4) SET_Z; else CLR_Z; break;
  6083.         case  5: if (CC5) SET_Z; else CLR_Z; break;
  6084.         case  6: if (CC6) SET_Z; else CLR_Z; break;
  6085.         case  7: if (CC7) SET_Z; else CLR_Z; break;
  6086.         case  8: if (CC8) SET_Z; else CLR_Z; break;
  6087.         case  9: if (CC9) SET_Z; else CLR_Z; break;
  6088.         case 10: if (CCA) SET_Z; else CLR_Z; break;
  6089.         case 11: if (CCB) SET_Z; else CLR_Z; break;
  6090.         case 12: if (CCC) SET_Z; else CLR_Z; break;
  6091.         case 13: if (CCD) SET_Z; else CLR_Z; break;
  6092.         case 14: if (CCE) SET_Z; else CLR_Z; break;
  6093.         case 15: if (CCF) SET_Z; else CLR_Z; break;
  6094.     }
  6095.     RW(src) += 2;
  6096.     if (--RW(cnt)) CLR_V; else SET_V;
  6097. }
  6098.  
  6099. /******************************************
  6100.  ldi     @rd,@rs,rr
  6101.  ldir     @rd,@rs,rr
  6102.  flags:  ---V--
  6103.  ******************************************/
  6104. static void ZBB_ssN0_0001_0000_rrrr_ddN0_x000(void)
  6105. {
  6106.     GET_SRC(OP0,NIB2);
  6107.     GET_CNT(OP1,NIB1);
  6108.     GET_DST(OP1,NIB2);
  6109.     GET_CCC(OP1,NIB3);
  6110.     WRMEM_W( RW(dst), RDMEM_W(RW(src)) );
  6111.     RW(dst) += 2;
  6112.     RW(src) += 2;
  6113.     if (--RW(cnt)) { CLR_V; if (cc == 0) PC -= 4; } else SET_V;
  6114. }
  6115.  
  6116. /******************************************
  6117.  cpsi     @rd,@rs,rr,cc
  6118.  flags:  CZSV--
  6119.  ******************************************/
  6120. static void ZBB_ssN0_0010_0000_rrrr_ddN0_cccc(void)
  6121. {
  6122.     GET_SRC(OP0,NIB2);
  6123.     GET_CCC(OP1,NIB3);
  6124.     GET_DST(OP1,NIB2);
  6125.     GET_CNT(OP1,NIB1);
  6126.     CPW( RDMEM_W(RW(dst)), RDMEM_W(RW(src)) );
  6127.     switch (cc) {
  6128.         case  0: if (CC0) SET_Z; else CLR_Z; break;
  6129.         case  1: if (CC1) SET_Z; else CLR_Z; break;
  6130.         case  2: if (CC2) SET_Z; else CLR_Z; break;
  6131.         case  3: if (CC3) SET_Z; else CLR_Z; break;
  6132.         case  4: if (CC4) SET_Z; else CLR_Z; break;
  6133.         case  5: if (CC5) SET_Z; else CLR_Z; break;
  6134.         case  6: if (CC6) SET_Z; else CLR_Z; break;
  6135.         case  7: if (CC7) SET_Z; else CLR_Z; break;
  6136.         case  8: if (CC8) SET_Z; else CLR_Z; break;
  6137.         case  9: if (CC9) SET_Z; else CLR_Z; break;
  6138.         case 10: if (CCA) SET_Z; else CLR_Z; break;
  6139.         case 11: if (CCB) SET_Z; else CLR_Z; break;
  6140.         case 12: if (CCC) SET_Z; else CLR_Z; break;
  6141.         case 13: if (CCD) SET_Z; else CLR_Z; break;
  6142.         case 14: if (CCE) SET_Z; else CLR_Z; break;
  6143.         case 15: if (CCF) SET_Z; else CLR_Z; break;
  6144.     }
  6145.     RW(dst) += 2;
  6146.     RW(src) += 2;
  6147.     if (--RW(cnt)) CLR_V; else SET_V;
  6148. }
  6149.  
  6150. /******************************************
  6151.  cpir     rd,@rs,rr,cc
  6152.  flags:  CZSV--
  6153.  ******************************************/
  6154. static void ZBB_ssN0_0100_0000_rrrr_dddd_cccc(void)
  6155. {
  6156.     GET_SRC(OP0,NIB2);
  6157.     GET_CCC(OP1,NIB3);
  6158.     GET_DST(OP1,NIB2);
  6159.     GET_CNT(OP1,NIB1);
  6160.     CPW( RW(dst), RDMEM_W(RW(src)) );
  6161.     switch (cc) {
  6162.         case  0: if (CC0) SET_Z; else CLR_Z; break;
  6163.         case  1: if (CC1) SET_Z; else CLR_Z; break;
  6164.         case  2: if (CC2) SET_Z; else CLR_Z; break;
  6165.         case  3: if (CC3) SET_Z; else CLR_Z; break;
  6166.         case  4: if (CC4) SET_Z; else CLR_Z; break;
  6167.         case  5: if (CC5) SET_Z; else CLR_Z; break;
  6168.         case  6: if (CC6) SET_Z; else CLR_Z; break;
  6169.         case  7: if (CC7) SET_Z; else CLR_Z; break;
  6170.         case  8: if (CC8) SET_Z; else CLR_Z; break;
  6171.         case  9: if (CC9) SET_Z; else CLR_Z; break;
  6172.         case 10: if (CCA) SET_Z; else CLR_Z; break;
  6173.         case 11: if (CCB) SET_Z; else CLR_Z; break;
  6174.         case 12: if (CCC) SET_Z; else CLR_Z; break;
  6175.         case 13: if (CCD) SET_Z; else CLR_Z; break;
  6176.         case 14: if (CCE) SET_Z; else CLR_Z; break;
  6177.         case 15: if (CCF) SET_Z; else CLR_Z; break;
  6178.     }
  6179.     RW(src) += 2;
  6180.     if (--RW(cnt)) { CLR_V; if (!(FCW & F_Z)) PC -= 4; } else SET_V;
  6181. }
  6182.  
  6183. /******************************************
  6184.  cpsir     @rd,@rs,rr,cc
  6185.  flags:  CZSV--
  6186.  ******************************************/
  6187. static void ZBB_ssN0_0110_0000_rrrr_ddN0_cccc(void)
  6188. {
  6189.     GET_SRC(OP0,NIB2);
  6190.     GET_CCC(OP1,NIB3);
  6191.     GET_DST(OP1,NIB2);
  6192.     GET_CNT(OP1,NIB1);
  6193.     CPW( RDMEM_W(RW(dst)), RDMEM_W(RW(src)) );
  6194.     switch (cc) {
  6195.         case  0: if (CC0) SET_Z; else CLR_Z; break;
  6196.         case  1: if (CC1) SET_Z; else CLR_Z; break;
  6197.         case  2: if (CC2) SET_Z; else CLR_Z; break;
  6198.         case  3: if (CC3) SET_Z; else CLR_Z; break;
  6199.         case  4: if (CC4) SET_Z; else CLR_Z; break;
  6200.         case  5: if (CC5) SET_Z; else CLR_Z; break;
  6201.         case  6: if (CC6) SET_Z; else CLR_Z; break;
  6202.         case  7: if (CC7) SET_Z; else CLR_Z; break;
  6203.         case  8: if (CC8) SET_Z; else CLR_Z; break;
  6204.         case  9: if (CC9) SET_Z; else CLR_Z; break;
  6205.         case 10: if (CCA) SET_Z; else CLR_Z; break;
  6206.         case 11: if (CCB) SET_Z; else CLR_Z; break;
  6207.         case 12: if (CCC) SET_Z; else CLR_Z; break;
  6208.         case 13: if (CCD) SET_Z; else CLR_Z; break;
  6209.         case 14: if (CCE) SET_Z; else CLR_Z; break;
  6210.         case 15: if (CCF) SET_Z; else CLR_Z; break;
  6211.     }
  6212.     RW(dst) += 2;
  6213.     RW(src) += 2;
  6214.     if (--RW(cnt)) { CLR_V; if (!(FCW & F_Z)) PC -= 4; } else SET_V;
  6215. }
  6216.  
  6217. /******************************************
  6218.  cpd     rd,@rs,rr,cc
  6219.  flags:  CZSV--
  6220.  ******************************************/
  6221. static void ZBB_ssN0_1000_0000_rrrr_dddd_cccc(void)
  6222. {
  6223.     GET_SRC(OP0,NIB2);
  6224.     GET_CCC(OP1,NIB3);
  6225.     GET_DST(OP1,NIB2);
  6226.     GET_CNT(OP1,NIB1);
  6227.     CPW( RW(dst), RDMEM_W(RW(src)) );
  6228.     switch (cc) {
  6229.         case  0: if (CC0) SET_Z; else CLR_Z; break;
  6230.         case  1: if (CC1) SET_Z; else CLR_Z; break;
  6231.         case  2: if (CC2) SET_Z; else CLR_Z; break;
  6232.         case  3: if (CC3) SET_Z; else CLR_Z; break;
  6233.         case  4: if (CC4) SET_Z; else CLR_Z; break;
  6234.         case  5: if (CC5) SET_Z; else CLR_Z; break;
  6235.         case  6: if (CC6) SET_Z; else CLR_Z; break;
  6236.         case  7: if (CC7) SET_Z; else CLR_Z; break;
  6237.         case  8: if (CC8) SET_Z; else CLR_Z; break;
  6238.         case  9: if (CC9) SET_Z; else CLR_Z; break;
  6239.         case 10: if (CCA) SET_Z; else CLR_Z; break;
  6240.         case 11: if (CCB) SET_Z; else CLR_Z; break;
  6241.         case 12: if (CCC) SET_Z; else CLR_Z; break;
  6242.         case 13: if (CCD) SET_Z; else CLR_Z; break;
  6243.         case 14: if (CCE) SET_Z; else CLR_Z; break;
  6244.         case 15: if (CCF) SET_Z; else CLR_Z; break;
  6245.     }
  6246.     RW(src) -= 2;
  6247.     if (--RW(cnt)) CLR_V; else SET_V;
  6248. }
  6249.  
  6250. /******************************************
  6251.  ldd     @rs,@rd,rr
  6252.  lddr     @rs,@rd,rr
  6253.  flags:  ---V--
  6254.  ******************************************/
  6255. static void ZBB_ssN0_1001_0000_rrrr_ddN0_x000(void)
  6256. {
  6257.     GET_SRC(OP0,NIB2);
  6258.     GET_CNT(OP1,NIB1);
  6259.     GET_DST(OP1,NIB2);
  6260.     GET_CCC(OP1,NIB3);
  6261.     WRMEM_W( RW(dst), RDMEM_W(RW(src)) );
  6262.     RW(dst) -= 2;
  6263.     RW(src) -= 2;
  6264.     if (--RW(cnt)) { CLR_V; if (cc == 0) PC -= 4; } else SET_V;
  6265. }
  6266.  
  6267. /******************************************
  6268.  cpsd     @rd,@rs,rr,cc
  6269.  flags:  CZSV--
  6270.  ******************************************/
  6271. static void ZBB_ssN0_1010_0000_rrrr_ddN0_cccc(void)
  6272. {
  6273.     GET_SRC(OP0,NIB2);
  6274.     GET_CCC(OP1,NIB3);
  6275.     GET_DST(OP1,NIB2);
  6276.     GET_CNT(OP1,NIB1);
  6277.     CPW( RDMEM_W(RW(dst)), RDMEM_W(RW(src)) );
  6278.     switch (cc) {
  6279.         case  0: if (CC0) SET_Z; else CLR_Z; break;
  6280.         case  1: if (CC1) SET_Z; else CLR_Z; break;
  6281.         case  2: if (CC2) SET_Z; else CLR_Z; break;
  6282.         case  3: if (CC3) SET_Z; else CLR_Z; break;
  6283.         case  4: if (CC4) SET_Z; else CLR_Z; break;
  6284.         case  5: if (CC5) SET_Z; else CLR_Z; break;
  6285.         case  6: if (CC6) SET_Z; else CLR_Z; break;
  6286.         case  7: if (CC7) SET_Z; else CLR_Z; break;
  6287.         case  8: if (CC8) SET_Z; else CLR_Z; break;
  6288.         case  9: if (CC9) SET_Z; else CLR_Z; break;
  6289.         case 10: if (CCA) SET_Z; else CLR_Z; break;
  6290.         case 11: if (CCB) SET_Z; else CLR_Z; break;
  6291.         case 12: if (CCC) SET_Z; else CLR_Z; break;
  6292.         case 13: if (CCD) SET_Z; else CLR_Z; break;
  6293.         case 14: if (CCE) SET_Z; else CLR_Z; break;
  6294.         case 15: if (CCF) SET_Z; else CLR_Z; break;
  6295.     }
  6296.     RW(dst) -= 2;
  6297.     RW(src) -= 2;
  6298.     if (--RW(cnt)) CLR_V; else SET_V;
  6299. }
  6300.  
  6301. /******************************************
  6302.  cpdr     rd,@rs,rr,cc
  6303.  flags:  CZSV--
  6304.  ******************************************/
  6305. static void ZBB_ssN0_1100_0000_rrrr_dddd_cccc(void)
  6306. {
  6307.     GET_SRC(OP0,NIB2);
  6308.     GET_CCC(OP1,NIB3);
  6309.     GET_DST(OP1,NIB2);
  6310.     GET_CNT(OP1,NIB1);
  6311.     CPW( RW(dst), RDMEM_W(RW(src)) );
  6312.     switch (cc) {
  6313.         case  0: if (CC0) SET_Z; else CLR_Z; break;
  6314.         case  1: if (CC1) SET_Z; else CLR_Z; break;
  6315.         case  2: if (CC2) SET_Z; else CLR_Z; break;
  6316.         case  3: if (CC3) SET_Z; else CLR_Z; break;
  6317.         case  4: if (CC4) SET_Z; else CLR_Z; break;
  6318.         case  5: if (CC5) SET_Z; else CLR_Z; break;
  6319.         case  6: if (CC6) SET_Z; else CLR_Z; break;
  6320.         case  7: if (CC7) SET_Z; else CLR_Z; break;
  6321.         case  8: if (CC8) SET_Z; else CLR_Z; break;
  6322.         case  9: if (CC9) SET_Z; else CLR_Z; break;
  6323.         case 10: if (CCA) SET_Z; else CLR_Z; break;
  6324.         case 11: if (CCB) SET_Z; else CLR_Z; break;
  6325.         case 12: if (CCC) SET_Z; else CLR_Z; break;
  6326.         case 13: if (CCD) SET_Z; else CLR_Z; break;
  6327.         case 14: if (CCE) SET_Z; else CLR_Z; break;
  6328.         case 15: if (CCF) SET_Z; else CLR_Z; break;
  6329.     }
  6330.     RW(src) -= 2;
  6331.     if (--RW(cnt)) { CLR_V; if (!(FCW & F_Z)) PC -= 4; } else SET_V;
  6332. }
  6333.  
  6334. /******************************************
  6335.  cpsdr     @rd,@rs,rr,cc
  6336.  flags:  CZSV--
  6337.  ******************************************/
  6338. static void ZBB_ssN0_1110_0000_rrrr_ddN0_cccc(void)
  6339. {
  6340.     GET_SRC(OP0,NIB2);
  6341.     GET_CCC(OP1,NIB3);
  6342.     GET_DST(OP1,NIB2);
  6343.     GET_CNT(OP1,NIB1);
  6344.     CPW( RDMEM_W(RW(dst)), RDMEM_W(RW(src)) );
  6345.     switch (cc) {
  6346.         case  0: if (CC0) SET_Z; else CLR_Z; break;
  6347.         case  1: if (CC1) SET_Z; else CLR_Z; break;
  6348.         case  2: if (CC2) SET_Z; else CLR_Z; break;
  6349.         case  3: if (CC3) SET_Z; else CLR_Z; break;
  6350.         case  4: if (CC4) SET_Z; else CLR_Z; break;
  6351.         case  5: if (CC5) SET_Z; else CLR_Z; break;
  6352.         case  6: if (CC6) SET_Z; else CLR_Z; break;
  6353.         case  7: if (CC7) SET_Z; else CLR_Z; break;
  6354.         case  8: if (CC8) SET_Z; else CLR_Z; break;
  6355.         case  9: if (CC9) SET_Z; else CLR_Z; break;
  6356.         case 10: if (CCA) SET_Z; else CLR_Z; break;
  6357.         case 11: if (CCB) SET_Z; else CLR_Z; break;
  6358.         case 12: if (CCC) SET_Z; else CLR_Z; break;
  6359.         case 13: if (CCD) SET_Z; else CLR_Z; break;
  6360.         case 14: if (CCE) SET_Z; else CLR_Z; break;
  6361.         case 15: if (CCF) SET_Z; else CLR_Z; break;
  6362.     }
  6363.     RW(dst) -= 2;
  6364.     RW(src) -= 2;
  6365.     if (--RW(cnt)) { CLR_V; if (!(FCW & F_Z)) PC -= 4; } else SET_V;
  6366. }
  6367.  
  6368. /******************************************
  6369.  rrdb     rbb,rba
  6370.  flags:  -Z----
  6371.  ******************************************/
  6372. static void ZBC_aaaa_bbbb(void)
  6373. {
  6374.     UINT8 b = Z.op[0] & 15;
  6375.     UINT8 a = (Z.op[0] >> 4) & 15;
  6376.     UINT8 tmp = RB(b);
  6377.     RB(a) = (RB(a) >> 4) | (RB(b) << 4);
  6378.     RB(b) = (RB(b) & 0xf0) | (tmp & 0x0f);
  6379.     if (RB(b)) CLR_Z; else SET_Z;
  6380. }
  6381.  
  6382. /******************************************
  6383.  ldk     rd,imm4
  6384.  flags:  ------
  6385.  ******************************************/
  6386. static void ZBD_dddd_imm4(void)
  6387. {
  6388.     GET_DST(OP0,NIB2);
  6389.     GET_IMM4(OP0,NIB3);
  6390.     RW(dst) = imm4;
  6391. }
  6392.  
  6393. /******************************************
  6394.  rldb     rbb,rba
  6395.  flags:  -Z----
  6396.  ******************************************/
  6397. static void ZBE_aaaa_bbbb(void)
  6398. {
  6399.     UINT8 b = Z.op[0] & 15;
  6400.     UINT8 a = (Z.op[0] >> 4) & 15;
  6401.     UINT8 tmp = RB(a);
  6402.     RB(a) = (RB(a) << 4) | (RB(b) & 0x0f);
  6403.     RB(b) = (RB(b) & 0xf0) | (tmp >> 4);
  6404.     if (RB(b)) CLR_Z; else SET_Z;
  6405. }
  6406.  
  6407. /******************************************
  6408.  rsvdbf
  6409.  flags:  ------
  6410.  ******************************************/
  6411. static void ZBF_imm8(void)
  6412. {
  6413.     GET_IMM8(0);
  6414.     LOG(("Z8K#%d %04x: rsvdbf $%02x\n", cpu_getactivecpu(), PC, imm8));
  6415.     if (FCW & F_EPU) {
  6416.         /* Z8001 EPU code goes here */
  6417.         (void)imm8;
  6418.     }
  6419.     (void)imm8;
  6420. }
  6421.  
  6422. /******************************************
  6423.  ldb     rbd,imm8
  6424.  flags:  ------
  6425.  ******************************************/
  6426. static void ZC_dddd_imm8(void)
  6427. {
  6428.     GET_DST(OP0,NIB1);
  6429.     GET_IMM8(0);
  6430.     RB(dst) = imm8;
  6431. }
  6432.  
  6433. /******************************************
  6434.  calr     dsp12
  6435.  flags:  ------
  6436.  ******************************************/
  6437. static void ZD_dsp12(void)
  6438. {
  6439.     INT16 dsp12 = Z.op[0] & 0xfff;
  6440.     PUSHW( SP, PC );
  6441.     dsp12 = (dsp12 & 2048) ? 4096 -2 * (dsp12 & 2047) : -2 * (dsp12 & 2047);
  6442.     PC += dsp12;
  6443.     change_pc16bew(PC);
  6444. }
  6445.  
  6446. /******************************************
  6447.  jr      cc,dsp8
  6448.  flags:  ------
  6449.  ******************************************/
  6450. static void ZE_cccc_dsp8(void)
  6451. {
  6452.     GET_DSP8;
  6453.     GET_CCC(OP0,NIB1);
  6454.     switch (cc) {
  6455.         case  0: if (CC0) PC += dsp8 * 2; break;
  6456.         case  1: if (CC1) PC += dsp8 * 2; break;
  6457.         case  2: if (CC2) PC += dsp8 * 2; break;
  6458.         case  3: if (CC3) PC += dsp8 * 2; break;
  6459.         case  4: if (CC4) PC += dsp8 * 2; break;
  6460.         case  5: if (CC5) PC += dsp8 * 2; break;
  6461.         case  6: if (CC6) PC += dsp8 * 2; break;
  6462.         case  7: if (CC7) PC += dsp8 * 2; break;
  6463.         case  8: if (CC8) PC += dsp8 * 2; break;
  6464.         case  9: if (CC9) PC += dsp8 * 2; break;
  6465.         case 10: if (CCA) PC += dsp8 * 2; break;
  6466.         case 11: if (CCB) PC += dsp8 * 2; break;
  6467.         case 12: if (CCC) PC += dsp8 * 2; break;
  6468.         case 13: if (CCD) PC += dsp8 * 2; break;
  6469.         case 14: if (CCE) PC += dsp8 * 2; break;
  6470.         case 15: if (CCF) PC += dsp8 * 2; break;
  6471.     }
  6472.     change_pc16bew(PC);
  6473. }
  6474.  
  6475. /******************************************
  6476.  dbjnz   rbd,dsp7
  6477.  flags:  ------
  6478.  ******************************************/
  6479. static void ZF_dddd_0dsp7(void)
  6480. {
  6481.     GET_DST(OP0,NIB1);
  6482.     GET_DSP7;
  6483.     RB(dst) -= 1;
  6484.     if (RB(dst)) {
  6485.         PC = PC - 2 * dsp7;
  6486.         change_pc16bew(PC);
  6487.     }
  6488. }
  6489.  
  6490. /******************************************
  6491.  djnz     rd,dsp7
  6492.  flags:  ------
  6493.  ******************************************/
  6494. static void ZF_dddd_1dsp7(void)
  6495. {
  6496.     GET_DST(OP0,NIB1);
  6497.     GET_DSP7;
  6498.     RW(dst) -= 1;
  6499.     if (RW(dst)) {
  6500.         PC = PC - 2 * dsp7;
  6501.         change_pc16bew(PC);
  6502.     }
  6503. }
  6504.  
  6505.  
  6506.